-
Notifications
You must be signed in to change notification settings - Fork 272
/
Copy pathscreen.test.tsx
66 lines (57 loc) · 1.97 KB
/
screen.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
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
import * as React from 'react';
import { View, Text } from 'react-native';
import { render, screen } from '..';
test('screen has the same queries as render result', () => {
const result = render(<Text>Mt. Everest</Text>);
expect(screen).toBe(result);
expect(screen.getByText('Mt. Everest')).toBeTruthy();
expect(screen.queryByText('Mt. Everest')).toBeTruthy();
expect(screen.getAllByText('Mt. Everest')).toHaveLength(1);
expect(screen.queryAllByText('Mt. Everest')).toHaveLength(1);
});
test('screen holds last render result', () => {
render(<Text>Mt. Everest</Text>);
render(<Text>Mt. Blanc</Text>);
const finalResult = render(<Text>Śnieżka</Text>);
expect(screen).toBe(finalResult);
expect(screen.getByText('Śnieżka')).toBeTruthy();
expect(screen.queryByText('Mt. Everest')).toBeFalsy();
expect(screen.queryByText('Mt. Blanc')).toBeFalsy();
});
test('screen works with updating rerender', () => {
const result = render(<Text>Mt. Everest</Text>);
expect(screen).toBe(result);
screen.rerender(<Text>Śnieżka</Text>);
expect(screen).toBe(result);
expect(screen.getByText('Śnieżka')).toBeTruthy();
});
test('screen works with nested re-mounting rerender', () => {
const result = render(
<View>
<Text>Mt. Everest</Text>
</View>
);
expect(screen).toBe(result);
screen.rerender(
<View>
<View>
<Text>Śnieżka</Text>
</View>
</View>
);
expect(screen).toBe(result);
expect(screen.getByText('Śnieżka')).toBeTruthy();
});
test('screen throws without render', () => {
expect(() => screen.root).toThrow('`render` method has not been called');
expect(() => screen.UNSAFE_root).toThrow(
'`render` method has not been called'
);
expect(() => screen.debug()).toThrow('`render` method has not been called');
expect(() => screen.debug.shallow()).toThrow(
'`render` method has not been called'
);
expect(() => screen.getByText('Mt. Everest')).toThrow(
'`render` method has not been called'
);
});