-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathindex.spec.js
123 lines (111 loc) · 3.24 KB
/
index.spec.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
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
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
jest.mock('detox');
const { expect: expectDetox } = require('detox');
const { getText, getProps, parseMessage } = require('./index');
const { iosMessages, androidMessages, iosNotFound, androidNotFound } = require('./exampleMessages');
describe('getText', () => {
it('should return iOS text', async () => {
const elem = 'boom';
expectDetox.mockImplementation(() => {
throw new Error(iosMessages['Step, One']);
});
const text = await getText(elem);
expect(text).toEqual('Step, One');
});
it('should return Android text', async () => {
const elem = 'boom';
expectDetox.mockImplementation(() => {
throw new Error(androidMessages['Step, One']);
});
const text = await getText(elem);
expect(text).toEqual('Step, One');
});
it('should throw exception for not found element on Android', async () => {
const elem = 'boom';
expectDetox.mockImplementation(() => {
throw new Error(androidNotFound);
});
let threw = false;
try {
await getText(elem);
} catch (e) {
threw = true;
}
expect(threw).toBeTruthy();
});
it('should throw exception for not found element on iOS', async () => {
const elem = 'boom';
expectDetox.mockImplementation(() => {
throw new Error(iosNotFound);
});
let threw = false;
try {
await getText(elem);
} catch (e) {
threw = true;
}
expect(threw).toBeTruthy();
});
it('should throw exception for unknown exception messages', async () => {
const elem = 'boom';
expectDetox.mockImplementation(() => {
throw new Error('Something');
});
let threw = false;
try {
await getText(elem);
} catch (e) {
threw = true;
}
expect(threw).toBeTruthy();
});
});
describe('getProps', () => {
it('should return iOS props', async () => {
const elem = 'boom';
expectDetox.mockImplementation(() => {
throw new Error(iosMessages['Step, One']);
});
const props = await getProps(elem);
expect(props).toMatchSnapshot();
});
it('should return Android props', async () => {
const elem = 'boom';
expectDetox.mockImplementation(() => {
throw new Error(androidMessages['Step, One']);
});
const props = await getProps(elem);
expect(props).toMatchSnapshot();
});
it('should throw exception for unknown exception messages', async () => {
const elem = 'boom';
expectDetox.mockImplementation(() => {
throw new Error('Something');
});
let threw = false;
try {
await getProps(elem);
} catch (e) {
threw = true;
}
expect(threw).toBeTruthy();
});
});
describe('parseMessage', () => {
it('should parse iOS matching string', () => {
Object.entries(iosMessages).forEach(([text, input]) => {
const output = parseMessage(input);
expect(output.text).toEqual(text);
expect(output).toMatchSnapshot();
});
});
it('should parse Android matching string', () => {
Object.entries(androidMessages).forEach(([text, input]) => {
const output = parseMessage(input);
expect(output.text).toEqual(text);
expect(output).toMatchSnapshot();
});
});
it('should throw error on unknown strings', () => {
expect(() => parseMessage('foo')).toThrow();
});
});