20
20
import "zone.js" ;
21
21
import "zone.js/testing" ;
22
22
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" ;
25
26
26
27
// Ensure Zone.js testing environment is properly configured
27
28
beforeEach ( ( ) => {
@@ -33,10 +34,6 @@ beforeEach(() => {
33
34
}
34
35
} ) ;
35
36
36
- // Import Angular testing utilities
37
- import { getTestBed } from "@angular/core/testing" ;
38
- import { BrowserDynamicTestingModule , platformBrowserDynamicTesting } from "@angular/platform-browser-dynamic/testing" ;
39
-
40
37
// Import Vitest utilities
41
38
import { expect , vi , afterEach , beforeEach } from "vitest" ;
42
39
import * as matchers from "@testing-library/jest-dom/matchers" ;
@@ -60,7 +57,6 @@ afterEach(() => {
60
57
declare global {
61
58
const spyOn : typeof vi . spyOn ;
62
59
const pending : ( reason ?: string ) => void ;
63
- const jasmine : any ;
64
60
}
65
61
66
62
// Define global test utilities
@@ -85,73 +81,11 @@ globalThis.spyOn = (obj: any, method: string) => {
85
81
reset : ( ) => spy . mockClear ( ) ,
86
82
all : ( ) => spy . mock . calls ,
87
83
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 : [ ] } ,
90
86
} ;
91
87
return spy ;
92
88
} ;
93
89
globalThis . pending = ( reason ?: string ) => {
94
90
throw new Error ( `Test pending: ${ reason || "No reason provided" } ` ) ;
95
91
} ;
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
- } ;
0 commit comments