From 36f434e49d24f0393950299486141a121d42e044 Mon Sep 17 00:00:00 2001 From: Matthieu Riegler Date: Wed, 16 Aug 2023 23:10:09 +0200 Subject: [PATCH] fix(core): guard the jasmine hooks (#51394) This commit fixes a regression introduced in #50063 Fixes #51382 PR Close #51394 --- packages/core/testing/src/test_hooks.ts | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/packages/core/testing/src/test_hooks.ts b/packages/core/testing/src/test_hooks.ts index ada3632d428..4165d3485db 100644 --- a/packages/core/testing/src/test_hooks.ts +++ b/packages/core/testing/src/test_hooks.ts @@ -16,12 +16,16 @@ import {resetFakeAsyncZone} from './fake_async'; import {TestBedImpl} from './test_bed'; // Reset the test providers and the fake async zone before each test. -beforeEach(getCleanupHook(false)); +// We keep a guard because somehow this file can make it into a bundle and be executed +// beforeEach is only defined when executing the tests +globalThis.beforeEach?.(getCleanupHook(false)); // We provide both a `beforeEach` and `afterEach`, because the updated behavior for // tearing down the module is supposed to run after the test so that we can associate // teardown errors with the correct test. -afterEach(getCleanupHook(true)); +// We keep a guard because somehow this file can make it into a bundle and be executed +// afterEach is only defined when executing the tests +globalThis.afterEach?.(getCleanupHook(true)); function getCleanupHook(expectedTeardownValue: boolean) { return () => {