Skip to content

Commit 423d5e6

Browse files
simonzsoltrolandszoke
authored andcommitted
test(examples): replace react-native tester
1 parent 5bc5c72 commit 423d5e6

File tree

3 files changed

+13
-21
lines changed

3 files changed

+13
-21
lines changed

__tests__/Clock.test.native.jsx

Lines changed: 13 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,20 +1,20 @@
11
import 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+
65
import sinon from 'sinon';
76
import App from '../examples/native-clock/App';
87

98
describe('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', () => {

package-lock.json

Lines changed: 0 additions & 9 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -106,7 +106,6 @@
106106
"react": "^16.12.0",
107107
"react-dom": "^16.13.0",
108108
"react-native": "^0.63.4",
109-
"react-native-testing-library": "^1.12.0",
110109
"react-router-dom": "^5.2.0",
111110
"react-test-renderer": "^17.0.1",
112111
"rollup": "^2.38.0",

0 commit comments

Comments
 (0)