11import React , { StrictMode } from 'react' ;
2- import {
3- render ,
4- flushMicrotasksQueue ,
5- } from 'react-native-testing-library' ;
2+
3+ import renderer from 'react-test-renderer' ;
4+
65import sinon from 'sinon' ;
76import App from '../examples/native-clock/App' ;
87
98describe ( 'Clock App' , ( ) => {
109 const clock = sinon . useFakeTimers ( ) ;
11- const { getByText, unmount } = render (
10+
11+ const app = renderer . create (
1212 < StrictMode >
1313 < App />
1414 </ StrictMode > ,
1515 ) ;
16- // flush the inital didMount effect
17- flushMicrotasksQueue ( ) ;
16+
17+ const { unmount } = app ;
1818
1919 const clearIntervalSpy = sinon . spy ( global , 'clearInterval' ) ;
2020
@@ -23,14 +23,16 @@ describe('Clock App', () => {
2323 clearIntervalSpy . restore ( ) ;
2424 } ) ;
2525
26- test ( 'should update to display the current time every second' , ( ) => {
27- expect ( getByText ( '12:00:00 AM' ) ) . toBeDefined ( ) ;
26+ test ( 'should update to display the current time every second' , async ( ) => {
27+ const textElement = app . root . findByType ( 'Text' ) ;
28+
29+ expect ( textElement . children [ 0 ] ) . toEqual ( '12:00:00 AM' ) ;
2830
2931 clock . tick ( 2000 ) ;
30- expect ( getByText ( '12:00:02 AM' ) ) . toBeDefined ( ) ;
32+ expect ( textElement . children [ 0 ] ) . toEqual ( '12:00:02 AM' ) ;
3133
3234 clock . tick ( 8500 ) ;
33- expect ( getByText ( '12:00:10 AM' ) ) . toBeDefined ( ) ;
35+ expect ( textElement . children [ 0 ] ) . toEqual ( '12:00:10 AM' ) ;
3436 } ) ;
3537
3638 test ( 'should clean up the interval timer when the component is unmounted' , ( ) => {
0 commit comments