1
1
import React from 'react'
2
- import { render , fireEvent } from '../'
2
+ import { render , fireEvent , screen } from '../'
3
3
4
4
class StopWatch extends React . Component {
5
5
state = { lapse : 0 , running : false }
@@ -37,12 +37,12 @@ class StopWatch extends React.Component {
37
37
}
38
38
}
39
39
40
- const wait = time => new Promise ( resolve => setTimeout ( resolve , time ) )
40
+ const sleep = t => new Promise ( resolve => setTimeout ( resolve , t ) )
41
41
42
42
test ( 'unmounts a component' , async ( ) => {
43
43
jest . spyOn ( console , 'error' ) . mockImplementation ( ( ) => { } )
44
- const { unmount, getByText , container} = render ( < StopWatch /> )
45
- fireEvent . click ( getByText ( 'Start' ) )
44
+ const { unmount, container} = render ( < StopWatch /> )
45
+ fireEvent . click ( screen . getByText ( 'Start' ) )
46
46
unmount ( )
47
47
// hey there reader! You don't need to have an assertion like this one
48
48
// this is just me making sure that the unmount function works.
@@ -51,6 +51,7 @@ test('unmounts a component', async () => {
51
51
// just wait to see if the interval is cleared or not
52
52
// if it's not, then we'll call setState on an unmounted component
53
53
// and get an error.
54
+ await sleep ( 5 )
54
55
// eslint-disable-next-line no-console
55
- await wait ( ( ) => expect ( console . error ) . not . toHaveBeenCalled ( ) )
56
+ expect ( console . error ) . not . toHaveBeenCalled ( )
56
57
} )
0 commit comments