Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 12 additions & 2 deletions .eslintrc.json
Original file line number Diff line number Diff line change
Expand Up @@ -10,11 +10,21 @@
"no-nested-ternary": "off",
"no-param-reassign": "off",
"func-names": "off",
"max-classes-per-file": "off"
"max-classes-per-file": "off",
"react/prefer-stateless-function": "off",
"react/prop-types": "off"
},
"globals": {
"window": true,
"EventTarget": true,
"WebSocket": true
"WebSocket": true,
"describe": true,
"afterAll": true,
"test": true,
"expect": true,
"afterEach": true,
"document": true,
"jest": true,
"Event": true
}
}
2 changes: 1 addition & 1 deletion __mocks__/react-native.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
// this is here to avoid duplicate react entries in the examples
// (one from the example's node_modules and one from the root's node_modules)
module.exports = require('react-native')
module.exports = require('react-native');
40 changes: 0 additions & 40 deletions __tests__/Clock.test.js

This file was deleted.

40 changes: 40 additions & 0 deletions __tests__/Clock.test.jsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
import React, { StrictMode } from 'react';
import { render, cleanup, act } from '@testing-library/react/pure';
import sinon from 'sinon';
import App from '../examples/clock/src/App';

describe('Clock App', () => {
const clock = sinon.useFakeTimers();
const { container, unmount } = render(
<StrictMode>
<App />
</StrictMode>,
);

const clearIntervalSpy = sinon.spy(global, 'clearInterval');

afterAll(() => {
cleanup();
clock.restore();
clearIntervalSpy.restore();
});

test('should update to display the current time every second', () => {
expect(container).toHaveTextContent('12:00:00 AM');

act(() => {
clock.tick(2000);
});
expect(container).toHaveTextContent('12:00:02 AM');

act(() => {
clock.tick(8500);
});
expect(container).toHaveTextContent('12:00:10 AM');
});

test('should clean up the interval timer when the component is unmounted', () => {
unmount();
expect(clearIntervalSpy.callCount).toBe(1);
});
});
37 changes: 0 additions & 37 deletions __tests__/Clock.test.native.js

This file was deleted.

40 changes: 40 additions & 0 deletions __tests__/Clock.test.native.jsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
import React, { StrictMode } from 'react';
import {
render,
flushMicrotasksQueue,
} from 'react-native-testing-library';
import sinon from 'sinon';
import App from '../examples/native-clock/App';

describe('Clock App', () => {
const clock = sinon.useFakeTimers();
const { getByText, unmount } = render(
<StrictMode>
<App />
</StrictMode>,
);
// flush the inital didMount effect
flushMicrotasksQueue();

const clearIntervalSpy = sinon.spy(global, 'clearInterval');

afterAll(() => {
clock.restore();
clearIntervalSpy.restore();
});

test('should update to display the current time every second', () => {
expect(getByText('12:00:00 AM')).toBeDefined();

clock.tick(2000);
expect(getByText('12:00:02 AM')).toBeDefined();

clock.tick(8500);
expect(getByText('12:00:10 AM')).toBeDefined();
});

test('should clean up the interval timer when the component is unmounted', () => {
unmount();
expect(clearIntervalSpy.callCount).toBe(1);
});
});
96 changes: 0 additions & 96 deletions __tests__/Contacts.test.js

This file was deleted.

Loading