7
7
} from '../../../test/_util/helpers' ;
8
8
import './fakeDevTools' ;
9
9
import 'preact/debug' ;
10
+ import { setupRerender } from 'preact/test-utils' ;
10
11
import * as PropTypes from 'prop-types' ;
11
12
12
13
// eslint-disable-next-line no-duplicate-imports
@@ -20,11 +21,13 @@ describe('debug', () => {
20
21
let scratch ;
21
22
let errors = [ ] ;
22
23
let warnings = [ ] ;
24
+ let rerender ;
23
25
24
26
beforeEach ( ( ) => {
25
27
errors = [ ] ;
26
28
warnings = [ ] ;
27
29
scratch = setupScratch ( ) ;
30
+ rerender = setupRerender ( ) ;
28
31
sinon . stub ( console , 'error' ) . callsFake ( e => errors . push ( e ) ) ;
29
32
sinon . stub ( console , 'warn' ) . callsFake ( w => warnings . push ( w ) ) ;
30
33
} ) ;
@@ -303,6 +306,22 @@ describe('debug', () => {
303
306
expect ( rerenderCount ) . to . equal ( 25 ) ;
304
307
} ) ;
305
308
309
+ it ( 'does not throw an error if a component renders many times in different cycles' , ( ) => {
310
+ let set ;
311
+ function TestComponent ( ) {
312
+ const [ count , setCount ] = useState ( 0 ) ;
313
+ set = ( ) => setCount ( count + 1 ) ;
314
+ return < div > { count } </ div > ;
315
+ }
316
+
317
+ render ( < TestComponent /> , scratch ) ;
318
+ for ( let i = 0 ; i < 30 ; i ++ ) {
319
+ set ( ) ;
320
+ rerender ( ) ;
321
+ }
322
+ expect ( scratch . innerHTML ) . to . equal ( '<div>30</div>' ) ;
323
+ } ) ;
324
+
306
325
describe ( 'duplicate keys' , ( ) => {
307
326
const List = props => < ul > { props . children } </ ul > ;
308
327
const ListItem = props => < li > { props . children } </ li > ;
0 commit comments