Skip to content

Commit 8abee7f

Browse files
committed
refactor: clean up test-setup.ts files
- Remove unnecessary Jasmine compatibility layer from test-setup.ts - Keep minimal spyOn compatibility for existing test patterns - Simplify imports and remove duplicate TestBed imports - Maintain Zone.js testing environment setup - All tests still pass: 94 passed | 1 skipped (95) The test-setup.ts files are now much cleaner while maintaining compatibility with existing test code that uses spyOn patterns.
1 parent 8314858 commit 8abee7f

File tree

2 files changed

+8
-127
lines changed

2 files changed

+8
-127
lines changed

examples/angular/src/test-setup.ts

Lines changed: 5 additions & 71 deletions
Original file line numberDiff line numberDiff line change
@@ -20,8 +20,9 @@
2020
import "zone.js";
2121
import "zone.js/testing";
2222

23-
// Set up Zone.js testing environment
24-
import { TestBed } from "@angular/core/testing";
23+
// Import Angular testing utilities
24+
import { getTestBed, TestBed } from "@angular/core/testing";
25+
import { BrowserDynamicTestingModule, platformBrowserDynamicTesting } from "@angular/platform-browser-dynamic/testing";
2526

2627
// Ensure Zone.js testing environment is properly configured
2728
beforeEach(() => {
@@ -33,10 +34,6 @@ beforeEach(() => {
3334
}
3435
});
3536

36-
// Import Angular testing utilities
37-
import { getTestBed } from "@angular/core/testing";
38-
import { BrowserDynamicTestingModule, platformBrowserDynamicTesting } from "@angular/platform-browser-dynamic/testing";
39-
4037
// Import Vitest utilities
4138
import { expect, vi, afterEach, beforeEach } from "vitest";
4239
import * as matchers from "@testing-library/jest-dom/matchers";
@@ -60,7 +57,6 @@ afterEach(() => {
6057
declare global {
6158
const spyOn: typeof vi.spyOn;
6259
const pending: (reason?: string) => void;
63-
const jasmine: any;
6460
}
6561

6662
// Define global test utilities
@@ -85,73 +81,11 @@ globalThis.spyOn = (obj: any, method: string) => {
8581
reset: () => spy.mockClear(),
8682
all: () => spy.mock.calls,
8783
count: () => spy.mock.calls.length,
88-
mostRecent: () => spy.mock.calls[spy.mock.calls.length - 1],
89-
any: () => spy.mock.calls.length > 0,
84+
mostRecent: () => spy.mock.calls[spy.mock.calls.length - 1] || { args: [] },
85+
first: () => spy.mock.calls[0] || { args: [] },
9086
};
9187
return spy;
9288
};
9389
globalThis.pending = (reason?: string) => {
9490
throw new Error(`Test pending: ${reason || "No reason provided"}`);
9591
};
96-
97-
// Mock Jasmine for compatibility
98-
globalThis.jasmine = {
99-
createSpy: (name: string) => {
100-
const spy = vi.fn();
101-
spy.and = {
102-
returnValue: (value: any) => {
103-
spy.mockReturnValue(value);
104-
return spy;
105-
},
106-
callFake: (fn: Function) => {
107-
spy.mockImplementation(fn);
108-
return spy;
109-
},
110-
callThrough: () => {
111-
// For createSpy, there's no original method to call through
112-
return spy;
113-
},
114-
};
115-
spy.calls = {
116-
reset: () => spy.mockClear(),
117-
all: () => spy.mock.calls,
118-
count: () => spy.mock.calls.length,
119-
mostRecent: () => spy.mock.calls[spy.mock.calls.length - 1],
120-
any: () => spy.mock.calls.length > 0,
121-
};
122-
return spy;
123-
},
124-
createSpyObj: (name: string, methods: string[], properties?: any) => {
125-
const obj: any = {};
126-
methods.forEach((method) => {
127-
const spy = vi.fn();
128-
// Add Jasmine-compatible methods
129-
spy.and = {
130-
returnValue: (value: any) => {
131-
spy.mockReturnValue(value);
132-
return spy;
133-
},
134-
callFake: (fn: Function) => {
135-
spy.mockImplementation(fn);
136-
return spy;
137-
},
138-
callThrough: () => {
139-
// For createSpyObj, there's no original method to call through
140-
return spy;
141-
},
142-
};
143-
spy.calls = {
144-
reset: () => spy.mockClear(),
145-
all: () => spy.mock.calls,
146-
count: () => spy.mock.calls.length,
147-
mostRecent: () => spy.mock.calls[spy.mock.calls.length - 1],
148-
any: () => spy.mock.calls.length > 0,
149-
};
150-
obj[method] = spy;
151-
});
152-
if (properties) {
153-
Object.assign(obj, properties);
154-
}
155-
return obj;
156-
},
157-
};

packages/angular/src/test-setup.ts

Lines changed: 3 additions & 56 deletions
Original file line numberDiff line numberDiff line change
@@ -20,8 +20,9 @@
2020
import "zone.js";
2121
import "zone.js/testing";
2222

23-
// Set up Zone.js testing environment
24-
import { TestBed } from "@angular/core/testing";
23+
// Import Angular testing utilities
24+
import { getTestBed, TestBed } from "@angular/core/testing";
25+
import { BrowserDynamicTestingModule, platformBrowserDynamicTesting } from "@angular/platform-browser-dynamic/testing";
2526

2627
// Ensure Zone.js testing environment is properly configured
2728
beforeEach(() => {
@@ -33,10 +34,6 @@ beforeEach(() => {
3334
}
3435
});
3536

36-
// Import Angular testing utilities
37-
import { getTestBed, TestBed } from "@angular/core/testing";
38-
import { BrowserDynamicTestingModule, platformBrowserDynamicTesting } from "@angular/platform-browser-dynamic/testing";
39-
4037
// Import Vitest utilities
4138
import { expect, vi, afterEach, beforeEach } from "vitest";
4239
import * as matchers from "@testing-library/jest-dom/matchers";
@@ -60,7 +57,6 @@ afterEach(() => {
6057
declare global {
6158
const spyOn: typeof vi.spyOn;
6259
const pending: (reason?: string) => void;
63-
const jasmine: any;
6460
}
6561

6662
// Define global test utilities
@@ -94,55 +90,6 @@ globalThis.pending = (reason?: string) => {
9490
throw new Error(`Test pending: ${reason || "No reason provided"}`);
9591
};
9692

97-
// Mock Jasmine for compatibility
98-
globalThis.jasmine = {
99-
createSpyObj: (name: string, methods: string[], properties?: any) => {
100-
const obj: any = {};
101-
methods.forEach((method) => {
102-
const spy = vi.fn();
103-
// Add Jasmine-compatible methods
104-
spy.and = {
105-
returnValue: (value: any) => {
106-
spy.mockReturnValue(value);
107-
return spy;
108-
},
109-
callFake: (fn: Function) => {
110-
spy.mockImplementation(fn);
111-
return spy;
112-
},
113-
callThrough: () => {
114-
spy.mockImplementation((...args: any[]) => obj[method](...args));
115-
return spy;
116-
},
117-
};
118-
obj[method] = spy;
119-
});
120-
if (properties) {
121-
Object.assign(obj, properties);
122-
}
123-
return obj;
124-
},
125-
createSpy: (name: string) => {
126-
const spy = vi.fn();
127-
// Add Jasmine-compatible methods
128-
spy.and = {
129-
returnValue: (value: any) => {
130-
spy.mockReturnValue(value);
131-
return spy;
132-
},
133-
callFake: (fn: Function) => {
134-
spy.mockImplementation(fn);
135-
return spy;
136-
},
137-
callThrough: () => {
138-
spy.mockImplementation((...args: any[]) => spy(...args));
139-
return spy;
140-
},
141-
};
142-
return spy;
143-
},
144-
};
145-
14693
// Mock global objects that might be needed for Firebase UI testing
14794
Object.defineProperty(window, "signInWithEmailAndPassword", {
14895
value: vi.fn(),

0 commit comments

Comments
 (0)