-
Notifications
You must be signed in to change notification settings - Fork 1
/
setupJest.js
73 lines (62 loc) · 1.92 KB
/
setupJest.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
expect.extend({
toBeNonEmptyString(received) {
expect(typeof received).toBe('string');
expect(received).not.toEqual('');
return {
pass: true,
message: () => 'Expected non-empty string',
};
},
});
expect.extend({
toBeInAvailableState(uid2, expectedAdvertisingToken) {
if (expectedAdvertisingToken) {
expect(uid2.getAdvertisingToken()).toBe(expectedAdvertisingToken);
} else if (uid2.getAdvertisingToken() !== '') {
expect(uid2.getAdvertisingToken()).toBeNonEmptyString();
}
expect(uid2.isLoginRequired()).toEqual(false);
return {
pass: true,
message: () =>
'Expected getAdvertisingToken() returns a token and isLoginRequired() returns false',
};
},
toBeInTemporarilyUnavailableState(uid2) {
expect(uid2.getAdvertisingToken()).toBeUndefined();
expect(uid2.isLoginRequired()).toEqual(false);
return {
pass: true,
message: () =>
'Expected getAdvertisingToken() returns undefined and isLoginRequired() returns false',
};
},
toBeInUnavailableState(uid2) {
expect(uid2.getAdvertisingToken()).toBeUndefined();
expect(uid2.isLoginRequired()).toEqual(true);
expect(uid2.hasOptedOut()).toEqual(false);
return {
pass: true,
message: () =>
'Expected getAdvertisingToken() returns undefined and isLoginRequired() returns true',
};
},
toBeInOptoutState(uid2) {
expect(uid2.getAdvertisingToken()).toBeUndefined();
expect(uid2.isLoginRequired()).toEqual(false);
expect(uid2.hasOptedOut()).toEqual(true);
return {
pass: true,
message: () =>
'Expected getAdvertisingToken() returns undefined and isLoginRequired() returns false',
};
},
});
const { TextEncoder, TextDecoder } = require('util');
global.TextEncoder = TextEncoder;
global.TextDecoder = TextDecoder;
Object.defineProperty(window, 'crypto', {
get() {
return require('crypto');
},
});