-
Notifications
You must be signed in to change notification settings - Fork 379
Expand file tree
/
Copy pathhelpers.test.ts
More file actions
61 lines (54 loc) · 1.92 KB
/
helpers.test.ts
File metadata and controls
61 lines (54 loc) · 1.92 KB
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
import type { NativeModule } from 'react-native';
import type { MockInstance } from 'vitest';
import { isNativeModuleLoaded, isValidCallback } from './helpers';
describe('helpers', () => {
let errorSpy: MockInstance;
beforeEach(() => {
errorSpy = vi.spyOn(console, 'error').mockImplementation(() => {});
});
describe('isValidCallback', () => {
test('should not throw when handler is a function', () => {
const handler = () => {};
expect(() => isValidCallback(handler)).not.toThrow();
});
test.each([
{ description: 'null', value: null },
{ description: 'undefined', value: undefined },
{ description: 'a string', value: 'not a function' },
{ description: 'a number', value: 123 },
{ description: 'an object', value: {} },
{ description: 'an array', value: [] },
{ description: 'a boolean', value: true },
])(
'should throw invariant error when handler is $description',
({ value }) => {
expect(() => isValidCallback(value as unknown as Function)).toThrow(
'Must provide a valid callback',
);
},
);
});
describe('isNativeModuleLoaded', () => {
test.each([
{ description: 'null', value: null as unknown as NativeModule },
{
description: 'undefined',
value: undefined as unknown as NativeModule,
},
])(
'should return false and log error when module is $description',
({ value }) => {
const result = isNativeModuleLoaded(value);
expect(result).toBe(false);
expect(errorSpy).toHaveBeenCalledTimes(1);
expect(errorSpy).toHaveBeenCalledWith(
'Could not load RNOneSignal native module. Make sure native dependencies are properly linked.',
);
},
);
test('should return true when module is loaded', () => {
const result = isNativeModuleLoaded({} as NativeModule);
expect(result).toBe(true);
});
});
});