forked from callstack/react-native-testing-library
-
Notifications
You must be signed in to change notification settings - Fork 0
/
auto-cleanup.js
33 lines (28 loc) · 805 Bytes
/
auto-cleanup.js
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
import React from 'react';
import { View } from 'react-native';
import { render } from '..';
let isMounted = false;
class Test extends React.Component<*> {
componentDidMount() {
isMounted = true;
}
componentWillUnmount() {
isMounted = false;
if (this.props.onUnmount) {
this.props.onUnmount();
}
}
render() {
return <View />;
}
}
// This just verifies that by importing RNTL in an environment which supports afterEach (like jest)
// we'll 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 automatically umounted after first test ends', () => {
expect(isMounted).toEqual(false);
});