-
Notifications
You must be signed in to change notification settings - Fork 278
Expand file tree
/
Copy pathcleanup.test.tsx
More file actions
37 lines (29 loc) · 859 Bytes
/
cleanup.test.tsx
File metadata and controls
37 lines (29 loc) · 859 Bytes
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
import * as React from 'react';
import { View } from 'react-native';
import { cleanup, render, unsafe_renderSync } from '../pure';
class Test extends React.Component<{ onUnmount: () => void }> {
componentWillUnmount() {
if (this.props.onUnmount) {
this.props.onUnmount();
}
}
render() {
return <View />;
}
}
test('cleanup after render', async () => {
const fn = jest.fn();
await render(<Test onUnmount={fn} />);
await render(<Test onUnmount={fn} />);
expect(fn).not.toHaveBeenCalled();
await cleanup();
expect(fn).toHaveBeenCalledTimes(2);
});
test('cleanup after unsafe_renderSync', async () => {
const fn = jest.fn();
unsafe_renderSync(<Test onUnmount={fn} />);
unsafe_renderSync(<Test onUnmount={fn} />);
expect(fn).not.toHaveBeenCalled();
await cleanup();
expect(fn).toHaveBeenCalledTimes(2);
});