Skip to content

Commit 0194ead

Browse files
committed
test(angular): updated angular testing framwork
1 parent 5106b7b commit 0194ead

File tree

1 file changed

+7
-15
lines changed

1 file changed

+7
-15
lines changed

examples/angular/src/test-setup.ts

Lines changed: 7 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -21,14 +21,13 @@ import "zone.js";
2121
import "zone.js/testing";
2222

2323
// Import Angular testing utilities
24-
import { getTestBed, TestBed } from "@angular/core/testing";
25-
import { BrowserDynamicTestingModule, platformBrowserDynamicTesting } from "@angular/platform-browser-dynamic/testing";
24+
import { TestBed } from "@angular/core/testing";
2625

2726
// Ensure Zone.js testing environment is properly configured
2827
beforeEach(() => {
2928
// Reset Zone.js state before each test
3029
if (typeof Zone !== "undefined") {
31-
Zone.current.fork({}).run(() => {
30+
Zone.current.fork({ name: "test-zone" }).run(() => {
3231
// Run each test in a fresh zone
3332
});
3433
}
@@ -41,13 +40,6 @@ import * as matchers from "@testing-library/jest-dom/matchers";
4140
// Extend Vitest's expect with jest-dom matchers
4241
expect.extend(matchers);
4342

44-
// Initialize the testing environment with Zone.js support
45-
if (!TestBed.platform) {
46-
TestBed.initTestEnvironment(BrowserDynamicTestingModule, platformBrowserDynamicTesting(), {
47-
teardown: { destroyAfterEach: false },
48-
});
49-
}
50-
5143
// Reset TestBed after each test to prevent configuration conflicts
5244
afterEach(() => {
5345
TestBed.resetTestingModule();
@@ -60,11 +52,11 @@ declare global {
6052
}
6153

6254
// Define global test utilities
63-
globalThis.spyOn = (obj: any, method: string) => {
55+
(globalThis as any).spyOn = (obj: any, method: string) => {
6456
const spy = vi.spyOn(obj, method);
6557
// Add Jasmine-compatible methods
66-
spy.and = {
67-
callFake: (fn: Function) => {
58+
(spy as any).and = {
59+
callFake: (fn: (...args: any[]) => any) => {
6860
spy.mockImplementation(fn);
6961
return spy;
7062
},
@@ -77,7 +69,7 @@ globalThis.spyOn = (obj: any, method: string) => {
7769
return spy;
7870
},
7971
};
80-
spy.calls = {
72+
(spy as any).calls = {
8173
reset: () => spy.mockClear(),
8274
all: () => spy.mock.calls,
8375
count: () => spy.mock.calls.length,
@@ -86,6 +78,6 @@ globalThis.spyOn = (obj: any, method: string) => {
8678
};
8779
return spy;
8880
};
89-
globalThis.pending = (reason?: string) => {
81+
(globalThis as any).pending = (reason?: string) => {
9082
throw new Error(`Test pending: ${reason || "No reason provided"}`);
9183
};

0 commit comments

Comments
 (0)