@@ -2,6 +2,7 @@ import { Fragment, createElement, render } from 'preact';
22import { setupScratch , teardown } from '../../../test/_util/helpers' ;
33import { useErrorBoundary , useLayoutEffect , useState } from 'preact/hooks' ;
44import { setupRerender } from 'preact/test-utils' ;
5+ import { vi } from 'vitest' ;
56
67/** @jsx createElement */
78
@@ -42,7 +43,7 @@ describe('errorBoundary', () => {
4243 } ) ;
4344
4445 it ( 'calls the errorBoundary callback' , ( ) => {
45- const spy = sinon . spy ( ) ;
46+ const spy = vi . fn ( ) ;
4647 const error = new Error ( 'test' ) ;
4748 const Throws = ( ) => {
4849 throw error ;
@@ -56,8 +57,8 @@ describe('errorBoundary', () => {
5657 render ( < App /> , scratch ) ;
5758 rerender ( ) ;
5859 expect ( scratch . innerHTML ) . to . equal ( '<p>Error</p>' ) ;
59- expect ( spy ) . to . be . calledOnce ;
60- expect ( spy ) . to . be . calledWith ( error , { } ) ;
60+ expect ( spy ) . toHaveBeenCalledOnce ( ) ;
61+ expect ( spy ) . toHaveBeenCalledWith ( error , { } ) ;
6162 } ) ;
6263
6364 it ( 'returns error' , ( ) => {
@@ -79,8 +80,8 @@ describe('errorBoundary', () => {
7980 } ) ;
8081
8182 it ( 'does not leave a stale closure' , ( ) => {
82- const spy = sinon . spy ( ) ,
83- spy2 = sinon . spy ( ) ;
83+ const spy = vi . fn ( ) ,
84+ spy2 = vi . fn ( ) ;
8485 let resetErr ;
8586 const error = new Error ( 'test' ) ;
8687 const Throws = ( ) => {
@@ -96,27 +97,27 @@ describe('errorBoundary', () => {
9697 render ( < App onError = { spy } /> , scratch ) ;
9798 rerender ( ) ;
9899 expect ( scratch . innerHTML ) . to . equal ( '<p>Error</p>' ) ;
99- expect ( spy ) . to . be . calledOnce ;
100- expect ( spy ) . to . be . calledWith ( error ) ;
100+ expect ( spy ) . toHaveBeenCalledOnce ( ) ;
101+ expect ( spy ) . toHaveBeenCalledWith ( error , { } ) ;
101102
102103 resetErr ( ) ;
103104 render ( < App onError = { spy2 } /> , scratch ) ;
104105 rerender ( ) ;
105- expect ( spy ) . to . be . calledOnce ;
106- expect ( spy2 ) . to . be . calledOnce ;
107- expect ( spy2 ) . to . be . calledWith ( error ) ;
106+ expect ( spy ) . toHaveBeenCalledOnce ( ) ;
107+ expect ( spy2 ) . toHaveBeenCalledOnce ( ) ;
108+ expect ( spy2 ) . toHaveBeenCalledWith ( error , { } ) ;
108109 expect ( scratch . innerHTML ) . to . equal ( '<p>Error</p>' ) ;
109110 } ) ;
110111
111112 it ( 'does not invoke old effects when a cleanup callback throws an error and is handled' , ( ) => {
112113 let throwErr = false ;
113- let thrower = sinon . spy ( ( ) => {
114+ let thrower = vi . fn ( ( ) => {
114115 if ( throwErr ) {
115116 throw new Error ( 'test' ) ;
116117 }
117118 } ) ;
118- let badEffect = sinon . spy ( ( ) => thrower ) ;
119- let goodEffect = sinon . spy ( ) ;
119+ let badEffect = vi . fn ( ( ) => thrower ) ;
120+ let goodEffect = vi . fn ( ) ;
120121
121122 function EffectThrowsError ( ) {
122123 useLayoutEffect ( badEffect ) ;
@@ -141,16 +142,16 @@ describe('errorBoundary', () => {
141142
142143 render ( < App /> , scratch ) ;
143144 expect ( scratch . innerHTML ) . to . equal ( '<span>Test</span>' ) ;
144- expect ( badEffect ) . to . be . calledOnce ;
145- expect ( goodEffect ) . to . be . calledOnce ;
145+ expect ( badEffect ) . toHaveBeenCalledOnce ( ) ;
146+ expect ( goodEffect ) . toHaveBeenCalledOnce ( ) ;
146147
147148 throwErr = true ;
148149 render ( < App /> , scratch ) ;
149150 rerender ( ) ;
150151 expect ( scratch . innerHTML ) . to . equal ( '<p>Error</p>' ) ;
151- expect ( thrower ) . to . be . calledOnce ;
152- expect ( badEffect ) . to . be . calledOnce ;
153- expect ( goodEffect ) . to . be . calledOnce ;
152+ expect ( thrower ) . toHaveBeenCalledOnce ( ) ;
153+ expect ( badEffect ) . toHaveBeenCalledOnce ( ) ;
154+ expect ( goodEffect ) . toHaveBeenCalledOnce ( ) ;
154155 } ) ;
155156
156157 it ( 'should not duplicate in lists where an item throws and the parent catches and returns a differing type' , ( ) => {
0 commit comments