-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathsafe.test.js
43 lines (36 loc) · 1.17 KB
/
safe.test.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
// safe.test.js
const safe = require('./safe');
describe('safe.array', () => {
test('returns the array if input is an array', () => {
const input = [1, 2, 3];
expect(safe.array(input)).toBe(input);
});
test('returns an empty array if input is not an array', () => {
const input = 'not an array';
expect(safe.array(input)).toEqual([]);
});
});
describe('safe.object', () => {
test('returns the object if input is an object', () => {
const input = { key: 'value' };
expect(safe.object(input)).toBe(input);
});
test('returns an empty object if input is not an object', () => {
const input = 'not an object';
expect(safe.object(input)).toEqual({});
});
test('should return an empty object for array input', () => {
const inputArray = [1, 2, 3];
expect(safe.object(inputArray)).toEqual({});
});
});
describe('safe.func', () => {
test('returns the function if input is a function', () => {
const input = () => {};
expect(safe.func(input)).toBe(input);
});
test('returns a dummy function if input is not a function', () => {
const input = 'not a function';
expect(typeof safe.func(input)).toBe('function');
});
});