-
Notifications
You must be signed in to change notification settings - Fork 44
/
Copy pathutils.ts
81 lines (73 loc) · 3.03 KB
/
utils.ts
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
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
import { View, Text, TextInput, Pressable, TouchableOpacity } from 'react-native';
import { checkReactElement, isEmpty } from '../utils';
describe('checkReactElement', () => {
test('ReactTestInstance does not throw for host elements', () => {
expect(() =>
// @ts-expect-error Passing incorrect Jest Matcher data
checkReactElement({ type: 'View' }, () => {}, {}),
).not.toThrow();
expect(() =>
// @ts-expect-error Passing incorrect Jest Matcher data
checkReactElement({ type: 'TextInput' }, () => {}, {}),
).not.toThrow();
expect(() =>
// @ts-expect-error Passing incorrect Jest Matcher data
checkReactElement({ type: 'View' }, () => {}, {}),
).not.toThrow();
});
test('ReactTestInstance does not throw for composite Text elements', () => {
expect(() =>
// @ts-expect-error Passing incorrect Jest Matcher data
checkReactElement({ type: Text }, () => {}, {}),
).not.toThrow();
});
test('ReactTestInstance does not throw for composite TextInput elements', () => {
expect(() =>
// @ts-expect-error Passing incorrect Jest Matcher data
checkReactElement({ type: TextInput }, () => {}, {}),
).not.toThrow();
});
test('it does throw for composite elements', () => {
expect(() =>
// @ts-expect-error Incorrect Test Renderer typings
checkReactElement({ type: View }, () => {}, {}),
).toThrowErrorMatchingInlineSnapshot(`
"expect(received).()
received value must be a host element or composite Text/TextInput element
Received has type: object
Received has value: {"type": [Function Component]}"
`);
expect(() =>
// @ts-expect-error Incorrect Test Renderer typings
checkReactElement({ type: Pressable }, () => {}, {}),
).toThrowErrorMatchingInlineSnapshot(`
"expect(received).()
received value must be a host element or composite Text/TextInput element
Received has type: object
Received has value: {"type": {"$$typeof": Symbol(react.memo), "compare": null, "type": {"$$typeof": Symbol(react.forward_ref), "render": [Function Pressable]}}}"
`);
expect(() =>
// @ts-expect-error Incorrect Test Renderer typings
checkReactElement({ type: TouchableOpacity }, () => {}, {}),
).toThrowErrorMatchingInlineSnapshot(`
"expect(received).()
received value must be a host element or composite Text/TextInput element
Received has type: object
Received has value: {"type": {"$$typeof": Symbol(react.forward_ref), "render": [Function anonymous]}}"
`);
});
});
test('isEmpty', () => {
expect(isEmpty(null)).toEqual(true);
expect(isEmpty(undefined)).toEqual(true);
expect(isEmpty('')).toEqual(true);
expect(isEmpty(' ')).toEqual(false);
expect(isEmpty([])).toEqual(true);
expect(isEmpty([[]])).toEqual(false);
expect(isEmpty({})).toEqual(true);
expect(isEmpty({ x: 0 })).toEqual(false);
expect(isEmpty(0)).toEqual(true);
expect(isEmpty(1)).toEqual(false);
expect(isEmpty(NaN)).toEqual(true);
expect(isEmpty([''])).toEqual(false);
});