-
Notifications
You must be signed in to change notification settings - Fork 273
/
Copy pathauto-cleanup-skip.test.tsx
40 lines (34 loc) · 1.04 KB
/
auto-cleanup-skip.test.tsx
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
import * as React from 'react';
import { View } from 'react-native';
let render: (element: React.ReactElement) => void;
beforeAll(() => {
process.env.RNTL_SKIP_AUTO_CLEANUP = 'true';
// eslint-disable-next-line @typescript-eslint/no-require-imports
const rntl = require('..');
render = rntl.render;
});
let isMounted = false;
class Test extends React.Component<{ onUnmount?(): void }> {
componentDidMount() {
isMounted = true;
}
componentWillUnmount() {
isMounted = false;
if (this.props.onUnmount) {
this.props.onUnmount();
}
}
render() {
return <View />;
}
}
// This just verifies that by importing RNTL in pure mode in an environment which supports
// afterEach (like jest) we won't get automatic cleanup between tests.
test('component is mounted, but not umounted before test ends', () => {
const fn = jest.fn();
render(<Test onUnmount={fn} />);
expect(fn).not.toHaveBeenCalled();
});
test('component is NOT automatically umounted after first test ends', () => {
expect(isMounted).toEqual(true);
});