@@ -2,6 +2,7 @@ import { Fragment, createElement, render } from 'preact';
2
2
import { setupScratch , teardown } from '../../../test/_util/helpers' ;
3
3
import { useErrorBoundary , useLayoutEffect , useState } from 'preact/hooks' ;
4
4
import { setupRerender } from 'preact/test-utils' ;
5
+ import { vi } from 'vitest' ;
5
6
6
7
/** @jsx createElement */
7
8
@@ -42,7 +43,7 @@ describe('errorBoundary', () => {
42
43
} ) ;
43
44
44
45
it ( 'calls the errorBoundary callback' , ( ) => {
45
- const spy = sinon . spy ( ) ;
46
+ const spy = vi . fn ( ) ;
46
47
const error = new Error ( 'test' ) ;
47
48
const Throws = ( ) => {
48
49
throw error ;
@@ -56,8 +57,8 @@ describe('errorBoundary', () => {
56
57
render ( < App /> , scratch ) ;
57
58
rerender ( ) ;
58
59
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 , { } ) ;
61
62
} ) ;
62
63
63
64
it ( 'returns error' , ( ) => {
@@ -79,8 +80,8 @@ describe('errorBoundary', () => {
79
80
} ) ;
80
81
81
82
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 ( ) ;
84
85
let resetErr ;
85
86
const error = new Error ( 'test' ) ;
86
87
const Throws = ( ) => {
@@ -96,27 +97,27 @@ describe('errorBoundary', () => {
96
97
render ( < App onError = { spy } /> , scratch ) ;
97
98
rerender ( ) ;
98
99
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 , { } ) ;
101
102
102
103
resetErr ( ) ;
103
104
render ( < App onError = { spy2 } /> , scratch ) ;
104
105
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 , { } ) ;
108
109
expect ( scratch . innerHTML ) . to . equal ( '<p>Error</p>' ) ;
109
110
} ) ;
110
111
111
112
it ( 'does not invoke old effects when a cleanup callback throws an error and is handled' , ( ) => {
112
113
let throwErr = false ;
113
- let thrower = sinon . spy ( ( ) => {
114
+ let thrower = vi . fn ( ( ) => {
114
115
if ( throwErr ) {
115
116
throw new Error ( 'test' ) ;
116
117
}
117
118
} ) ;
118
- let badEffect = sinon . spy ( ( ) => thrower ) ;
119
- let goodEffect = sinon . spy ( ) ;
119
+ let badEffect = vi . fn ( ( ) => thrower ) ;
120
+ let goodEffect = vi . fn ( ) ;
120
121
121
122
function EffectThrowsError ( ) {
122
123
useLayoutEffect ( badEffect ) ;
@@ -141,16 +142,16 @@ describe('errorBoundary', () => {
141
142
142
143
render ( < App /> , scratch ) ;
143
144
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 ( ) ;
146
147
147
148
throwErr = true ;
148
149
render ( < App /> , scratch ) ;
149
150
rerender ( ) ;
150
151
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 ( ) ;
154
155
} ) ;
155
156
156
157
it ( 'should not duplicate in lists where an item throws and the parent catches and returns a differing type' , ( ) => {
0 commit comments