Skip to content

Commit 7ef4743

Browse files
rolandszokesolkimicreb
authored andcommitted
ci(lint): lint tests before commits
* refactor(tests): lint test files
1 parent 7a5cbcd commit 7ef4743

22 files changed

+813
-717
lines changed

.eslintrc.json

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,11 +10,21 @@
1010
"no-nested-ternary": "off",
1111
"no-param-reassign": "off",
1212
"func-names": "off",
13-
"max-classes-per-file": "off"
13+
"max-classes-per-file": "off",
14+
"react/prefer-stateless-function": "off",
15+
"react/prop-types": "off"
1416
},
1517
"globals": {
1618
"window": true,
1719
"EventTarget": true,
18-
"WebSocket": true
20+
"WebSocket": true,
21+
"describe": true,
22+
"afterAll": true,
23+
"test": true,
24+
"expect": true,
25+
"afterEach": true,
26+
"document": true,
27+
"jest": true,
28+
"Event": true
1929
}
2030
}

__mocks__/react-native.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,3 @@
11
// this is here to avoid duplicate react entries in the examples
22
// (one from the example's node_modules and one from the root's node_modules)
3-
module.exports = require('react-native')
3+
module.exports = require('react-native');

__tests__/Clock.test.js

Lines changed: 0 additions & 40 deletions
This file was deleted.

__tests__/Clock.test.jsx

Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
import React, { StrictMode } from 'react';
2+
import { render, cleanup, act } from '@testing-library/react/pure';
3+
import sinon from 'sinon';
4+
import App from '../examples/clock/src/App';
5+
6+
describe('Clock App', () => {
7+
const clock = sinon.useFakeTimers();
8+
const { container, unmount } = render(
9+
<StrictMode>
10+
<App />
11+
</StrictMode>,
12+
);
13+
14+
const clearIntervalSpy = sinon.spy(global, 'clearInterval');
15+
16+
afterAll(() => {
17+
cleanup();
18+
clock.restore();
19+
clearIntervalSpy.restore();
20+
});
21+
22+
test('should update to display the current time every second', () => {
23+
expect(container).toHaveTextContent('12:00:00 AM');
24+
25+
act(() => {
26+
clock.tick(2000);
27+
});
28+
expect(container).toHaveTextContent('12:00:02 AM');
29+
30+
act(() => {
31+
clock.tick(8500);
32+
});
33+
expect(container).toHaveTextContent('12:00:10 AM');
34+
});
35+
36+
test('should clean up the interval timer when the component is unmounted', () => {
37+
unmount();
38+
expect(clearIntervalSpy.callCount).toBe(1);
39+
});
40+
});

__tests__/Clock.test.native.js

Lines changed: 0 additions & 37 deletions
This file was deleted.

__tests__/Clock.test.native.jsx

Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
import React, { StrictMode } from 'react';
2+
import {
3+
render,
4+
flushMicrotasksQueue,
5+
} from 'react-native-testing-library';
6+
import sinon from 'sinon';
7+
import App from '../examples/native-clock/App';
8+
9+
describe('Clock App', () => {
10+
const clock = sinon.useFakeTimers();
11+
const { getByText, unmount } = render(
12+
<StrictMode>
13+
<App />
14+
</StrictMode>,
15+
);
16+
// flush the inital didMount effect
17+
flushMicrotasksQueue();
18+
19+
const clearIntervalSpy = sinon.spy(global, 'clearInterval');
20+
21+
afterAll(() => {
22+
clock.restore();
23+
clearIntervalSpy.restore();
24+
});
25+
26+
test('should update to display the current time every second', () => {
27+
expect(getByText('12:00:00 AM')).toBeDefined();
28+
29+
clock.tick(2000);
30+
expect(getByText('12:00:02 AM')).toBeDefined();
31+
32+
clock.tick(8500);
33+
expect(getByText('12:00:10 AM')).toBeDefined();
34+
});
35+
36+
test('should clean up the interval timer when the component is unmounted', () => {
37+
unmount();
38+
expect(clearIntervalSpy.callCount).toBe(1);
39+
});
40+
});

__tests__/Contacts.test.js

Lines changed: 0 additions & 96 deletions
This file was deleted.

0 commit comments

Comments
 (0)