88 checkHangingAct ,
99 getConsoleErrorSpy ,
1010} from "../../../test/shared/utils" ;
11+ import { describe , expect , beforeEach , afterEach , vi , it } from "vitest" ;
1112
1213const MANAGED_COMPONENT = 1 ;
1314const MANAGED_HOOK = 2 ;
@@ -52,7 +53,7 @@ describe("useSignals", () => {
5253 scratch = document . createElement ( "div" ) ;
5354 document . body . appendChild ( scratch ) ;
5455 root = await createRoot ( scratch ) ;
55- getConsoleErrorSpy ( ) . resetHistory ( ) ;
56+ getConsoleErrorSpy ( ) . mockClear ( ) ;
5657 } ) ;
5758
5859 afterEach ( async ( ) => {
@@ -142,23 +143,23 @@ describe("useSignals", () => {
142143 } ) ;
143144
144145 it ( "should not rerender components when signals they use do not change" , async ( ) => {
145- const child1Spy = sinon . spy ( ) ;
146+ const child1Spy = vi . fn ( ) ;
146147 const signal1 = signal ( 0 ) ;
147148 function Child1 ( ) {
148149 child1Spy ( ) ;
149150 useSignals ( ) ;
150151 return < p > { signal1 . value } </ p > ;
151152 }
152153
153- const child2Spy = sinon . spy ( ) ;
154+ const child2Spy = vi . fn ( ) ;
154155 const signal2 = signal ( 0 ) ;
155156 function Child2 ( ) {
156157 child2Spy ( ) ;
157158 useSignals ( ) ;
158159 return < p > { signal2 . value } </ p > ;
159160 }
160161
161- const parentSpy = sinon . spy ( ) ;
162+ const parentSpy = vi . fn ( ) ;
162163 function Parent ( ) {
163164 parentSpy ( ) ;
164165 return (
@@ -170,39 +171,39 @@ describe("useSignals", () => {
170171 }
171172
172173 function resetSpies ( ) {
173- child1Spy . resetHistory ( ) ;
174- child2Spy . resetHistory ( ) ;
175- parentSpy . resetHistory ( ) ;
174+ child1Spy . mockClear ( ) ;
175+ child2Spy . mockClear ( ) ;
176+ parentSpy . mockClear ( ) ;
176177 }
177178
178179 resetSpies ( ) ;
179180 await render ( < Parent /> ) ;
180181 expect ( scratch . innerHTML ) . to . equal ( "<p>0</p><p>0</p>" ) ;
181- expect ( child1Spy ) . to . have . been . calledOnce ;
182- expect ( child2Spy ) . to . have . been . calledOnce ;
183- expect ( parentSpy ) . to . have . been . calledOnce ;
182+ expect ( child1Spy ) . toHaveBeenCalledOnce ( ) ;
183+ expect ( child2Spy ) . toHaveBeenCalledOnce ( ) ;
184+ expect ( parentSpy ) . toHaveBeenCalledOnce ( ) ;
184185
185186 resetSpies ( ) ;
186187 await act ( ( ) => {
187188 signal1 . value += 1 ;
188189 } ) ;
189190 expect ( scratch . innerHTML ) . to . equal ( "<p>1</p><p>0</p>" ) ;
190- expect ( child1Spy ) . to . have . been . calledOnce ;
191- expect ( child2Spy ) . to . not . have . been . called ;
192- expect ( parentSpy ) . to . not . have . been . called ;
191+ expect ( child1Spy ) . toHaveBeenCalledOnce ( ) ;
192+ expect ( child2Spy ) . not . toHaveBeenCalled ( ) ;
193+ expect ( parentSpy ) . not . toHaveBeenCalled ( ) ;
193194
194195 resetSpies ( ) ;
195196 await act ( ( ) => {
196197 signal2 . value += 1 ;
197198 } ) ;
198199 expect ( scratch . innerHTML ) . to . equal ( "<p>1</p><p>1</p>" ) ;
199- expect ( child1Spy ) . to . not . have . been . called ;
200- expect ( child2Spy ) . to . have . been . calledOnce ;
201- expect ( parentSpy ) . to . not . have . been . called ;
200+ expect ( child1Spy ) . not . toHaveBeenCalled ( ) ;
201+ expect ( child2Spy ) . toHaveBeenCalledOnce ( ) ;
202+ expect ( parentSpy ) . not . toHaveBeenCalled ( ) ;
202203 } ) ;
203204
204205 it ( "should not rerender components when signals they use change but they are not mounted" , async ( ) => {
205- const child1Spy = sinon . spy ( ) ;
206+ const child1Spy = vi . fn ( ) ;
206207 const signal1 = signal ( 0 ) ;
207208 function Child ( ) {
208209 child1Spy ( ) ;
@@ -231,11 +232,11 @@ describe("useSignals", () => {
231232 await act ( ( ) => {
232233 signal1 . value += 1 ;
233234 } ) ;
234- expect ( child1Spy ) . to . have . been . calledTwice ;
235+ expect ( child1Spy ) . toHaveBeenCalledTimes ( 2 ) ;
235236 } ) ;
236237
237238 it ( "should not rerender components that only update signals in event handlers" , async ( ) => {
238- const buttonSpy = sinon . spy ( ) ;
239+ const buttonSpy = vi . fn ( ) ;
239240 function AddOneButton ( { num } : { num : Signal < number > } ) {
240241 useSignals ( ) ;
241242 buttonSpy ( ) ;
@@ -250,7 +251,7 @@ describe("useSignals", () => {
250251 ) ;
251252 }
252253
253- const displaySpy = sinon . spy ( ) ;
254+ const displaySpy = vi . fn ( ) ;
254255 function DisplayNumber ( { num } : { num : Signal < number > } ) {
255256 useSignals ( ) ;
256257 displaySpy ( ) ;
@@ -269,20 +270,20 @@ describe("useSignals", () => {
269270
270271 await render ( < App /> ) ;
271272 expect ( scratch . innerHTML ) . to . equal ( "<button>Add One</button><p>0</p>" ) ;
272- expect ( buttonSpy ) . to . have . been . calledOnce ;
273- expect ( displaySpy ) . to . have . been . calledOnce ;
273+ expect ( buttonSpy ) . toHaveBeenCalledOnce ( ) ;
274+ expect ( displaySpy ) . toHaveBeenCalledOnce ( ) ;
274275
275276 await act ( ( ) => {
276277 scratch . querySelector ( "button" ) ! . click ( ) ;
277278 } ) ;
278279
279280 expect ( scratch . innerHTML ) . to . equal ( "<button>Add One</button><p>1</p>" ) ;
280- expect ( buttonSpy ) . to . have . been . calledOnce ;
281- expect ( displaySpy ) . to . have . been . calledTwice ;
281+ expect ( buttonSpy ) . toHaveBeenCalledOnce ( ) ;
282+ expect ( displaySpy ) . toHaveBeenCalledTimes ( 2 ) ;
282283 } ) ;
283284
284285 it ( "should not rerender components that only read signals in event handlers" , async ( ) => {
285- const buttonSpy = sinon . spy ( ) ;
286+ const buttonSpy = vi . fn ( ) ;
286287 function AddOneButton ( { num } : { num : Signal < number > } ) {
287288 useSignals ( ) ;
288289 buttonSpy ( ) ;
@@ -297,7 +298,7 @@ describe("useSignals", () => {
297298 ) ;
298299 }
299300
300- const displaySpy = sinon . spy ( ) ;
301+ const displaySpy = vi . fn ( ) ;
301302 function DisplayNumber ( { num } : { num : Signal < number > } ) {
302303 useSignals ( ) ;
303304 displaySpy ( ) ;
@@ -316,42 +317,42 @@ describe("useSignals", () => {
316317 }
317318
318319 function resetSpies ( ) {
319- buttonSpy . resetHistory ( ) ;
320- displaySpy . resetHistory ( ) ;
320+ buttonSpy . mockClear ( ) ;
321+ displaySpy . mockClear ( ) ;
321322 }
322323
323324 resetSpies ( ) ;
324325 await render ( < App /> ) ;
325326 expect ( scratch . innerHTML ) . to . equal ( "<button>Add One</button><p>0</p>" ) ;
326- expect ( buttonSpy ) . to . have . been . calledOnce ;
327- expect ( displaySpy ) . to . have . been . calledOnce ;
327+ expect ( buttonSpy ) . toHaveBeenCalledOnce ( ) ;
328+ expect ( displaySpy ) . toHaveBeenCalledOnce ( ) ;
328329
329330 resetSpies ( ) ;
330331 await act ( ( ) => {
331332 scratch . querySelector ( "button" ) ! . click ( ) ;
332333 } ) ;
333334
334335 expect ( scratch . innerHTML ) . to . equal ( "<button>Add One</button><p>2</p>" ) ;
335- expect ( buttonSpy ) . to . not . have . been . called ;
336- expect ( displaySpy ) . to . have . been . calledOnce ;
336+ expect ( buttonSpy ) . not . toHaveBeenCalled ( ) ;
337+ expect ( displaySpy ) . toHaveBeenCalledOnce ( ) ;
337338
338339 resetSpies ( ) ;
339340 await act ( ( ) => {
340341 adder . value += 1 ;
341342 } ) ;
342343
343344 expect ( scratch . innerHTML ) . to . equal ( "<button>Add One</button><p>2</p>" ) ;
344- expect ( buttonSpy ) . to . not . have . been . called ;
345- expect ( displaySpy ) . to . not . have . been . called ;
345+ expect ( buttonSpy ) . not . toHaveBeenCalled ( ) ;
346+ expect ( displaySpy ) . not . toHaveBeenCalled ( ) ;
346347
347348 resetSpies ( ) ;
348349 await act ( ( ) => {
349350 scratch . querySelector ( "button" ) ! . click ( ) ;
350351 } ) ;
351352
352353 expect ( scratch . innerHTML ) . to . equal ( "<button>Add One</button><p>5</p>" ) ;
353- expect ( buttonSpy ) . to . not . have . been . called ;
354- expect ( displaySpy ) . to . have . been . calledOnce ;
354+ expect ( buttonSpy ) . not . toHaveBeenCalled ( ) ;
355+ expect ( displaySpy ) . toHaveBeenCalledOnce ( ) ;
355356 } ) ;
356357
357358 it ( "should properly rerender components that use custom hooks" , async ( ) => {
0 commit comments