11import React , { createElement } from 'preact/compat' ;
22import { setupRerender } from 'preact/test-utils' ;
33import { setupScratch , teardown } from '../../../test/_util/helpers' ;
4+ import { vi } from 'vitest' ;
45
56describe ( 'PureComponent' , ( ) => {
67 /** @type {HTMLDivElement } */
@@ -23,7 +24,7 @@ describe('PureComponent', () => {
2324 } ) ;
2425
2526 it ( 'should pass props in constructor' , ( ) => {
26- let spy = sinon . spy ( ) ;
27+ let spy = vi . fn ( ) ;
2728 class Foo extends React . PureComponent {
2829 constructor ( props ) {
2930 super ( props ) ;
@@ -34,7 +35,7 @@ describe('PureComponent', () => {
3435 React . render ( < Foo foo = "bar" /> , scratch ) ;
3536
3637 let expected = { foo : 'bar' } ;
37- expect ( spy ) . to . be . calledWithMatch ( expected , expected ) ;
38+ expect ( spy ) . toHaveBeenCalledWith ( expected , expected ) ;
3839 } ) ;
3940
4041 it ( 'should pass context in constructor' , ( ) => {
@@ -54,14 +55,14 @@ describe('PureComponent', () => {
5455 }
5556 }
5657
57- sinon . spy ( Foo . prototype , 'render' ) ;
58+ vi . spyOn ( Foo . prototype , 'render' ) ;
5859
5960 const PROPS = { foo : 'bar' } ;
6061 React . render ( < Foo { ...PROPS } /> , scratch ) ;
6162
62- expect ( Foo . prototype . render )
63- . to . have . been . calledOnce . and . to . have . been . calledWithMatch ( PROPS , { } , { } )
64- . and . to . have . returned ( sinon . match ( { type : 'div' , props : PROPS } ) ) ;
63+ expect ( Foo . prototype . render ) . toHaveBeenCalledOnce ( ) ;
64+ expect ( Foo . prototype . render ) . toHaveBeenCalledWith ( PROPS , { } , { } ) ;
65+ expect ( Foo . prototype . render ) . toHaveReturned ( { type : 'div' , props : PROPS } ) ;
6566 expect ( instance . props ) . to . deep . equal ( PROPS ) ;
6667 expect ( instance . state ) . to . deep . equal ( { } ) ;
6768 expect ( instance . context ) . to . deep . equal ( { } ) ;
@@ -70,8 +71,8 @@ describe('PureComponent', () => {
7071 } ) ;
7172
7273 it ( 'should ignore the __source variable' , ( ) => {
73- const pureSpy = sinon . spy ( ) ;
74- const appSpy = sinon . spy ( ) ;
74+ const pureSpy = vi . fn ( ) ;
75+ const appSpy = vi . fn ( ) ;
7576 /** @type {(v) => void } */
7677 let set ;
7778 class Pure extends React . PureComponent {
@@ -89,13 +90,13 @@ describe('PureComponent', () => {
8990 } ;
9091
9192 React . render ( < App /> , scratch ) ;
92- expect ( appSpy ) . to . be . calledOnce ;
93- expect ( pureSpy ) . to . be . calledOnce ;
93+ expect ( appSpy ) . toHaveBeenCalledOnce ( ) ;
94+ expect ( pureSpy ) . toHaveBeenCalledOnce ( ) ;
9495
9596 set ( 1 ) ;
9697 rerender ( ) ;
97- expect ( appSpy ) . to . be . calledTwice ;
98- expect ( pureSpy ) . to . be . calledOnce ;
98+ expect ( appSpy ) . toHaveBeenCalledTimes ( 2 ) ;
99+ expect ( pureSpy ) . toHaveBeenCalledOnce ( ) ;
99100 } ) ;
100101
101102 it ( 'should only re-render when props or state change' , ( ) => {
@@ -104,39 +105,39 @@ describe('PureComponent', () => {
104105 return < div /> ;
105106 }
106107 }
107- let spy = sinon . spy ( C . prototype , 'render' ) ;
108+ let spy = vi . spyOn ( C . prototype , 'render' ) ;
108109
109110 let inst = React . render ( < C /> , scratch ) ;
110- expect ( spy ) . to . have . been . calledOnce ;
111- spy . resetHistory ( ) ;
111+ expect ( spy ) . toHaveBeenCalledOnce ( ) ;
112+ spy . mockClear ( ) ;
112113
113114 inst = React . render ( < C /> , scratch ) ;
114- expect ( spy ) . not . to . have . been . called ;
115+ expect ( spy ) . not . toHaveBeenCalled ( ) ;
115116
116117 let b = { foo : 'bar' } ;
117118 inst = React . render ( < C a = "a" b = { b } /> , scratch ) ;
118- expect ( spy ) . to . have . been . calledOnce ;
119- spy . resetHistory ( ) ;
119+ expect ( spy ) . toHaveBeenCalledOnce ( ) ;
120+ spy . mockClear ( ) ;
120121
121122 inst = React . render ( < C a = "a" b = { b } /> , scratch ) ;
122- expect ( spy ) . not . to . have . been . called ;
123+ expect ( spy ) . not . toHaveBeenCalled ( ) ;
123124
124125 inst . setState ( { } ) ;
125126 rerender ( ) ;
126- expect ( spy ) . not . to . have . been . called ;
127+ expect ( spy ) . not . toHaveBeenCalled ( ) ;
127128
128129 inst . setState ( { a : 'a' , b } ) ;
129130 rerender ( ) ;
130- expect ( spy ) . to . have . been . calledOnce ;
131- spy . resetHistory ( ) ;
131+ expect ( spy ) . toHaveBeenCalledOnce ( ) ;
132+ spy . mockClear ( ) ;
132133
133134 inst . setState ( { a : 'a' , b } ) ;
134135 rerender ( ) ;
135- expect ( spy ) . not . to . have . been . called ;
136+ expect ( spy ) . not . toHaveBeenCalled ( ) ;
136137 } ) ;
137138
138139 it ( 'should update when props are removed' , ( ) => {
139- let spy = sinon . spy ( ) ;
140+ let spy = vi . fn ( ) ;
140141 class App extends React . PureComponent {
141142 render ( ) {
142143 spy ( ) ;
@@ -146,7 +147,7 @@ describe('PureComponent', () => {
146147
147148 React . render ( < App a = "foo" /> , scratch ) ;
148149 React . render ( < App /> , scratch ) ;
149- expect ( spy ) . to . be . calledTwice ;
150+ expect ( spy ) . toHaveBeenCalledTimes ( 2 ) ;
150151 } ) ;
151152
152153 it ( 'should have "isPureReactComponent" property' , ( ) => {
0 commit comments