forked from typescript-eslint/typescript-eslint
-
Notifications
You must be signed in to change notification settings - Fork 0
/
applyDefault.test.ts
76 lines (67 loc) · 1.93 KB
/
applyDefault.test.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
import { ESLintUtils } from '../../src';
describe('applyDefault', () => {
it('returns a clone of the default if no options given', () => {
const defaults = [{ prop: 'setting' }];
const user = null;
const result = ESLintUtils.applyDefault(defaults, user);
expect(result).toStrictEqual(defaults);
expect(result).not.toBe(defaults);
});
it('returns applies a deepMerge to each element in the array', () => {
const defaults: Record<string, string>[] = [
{
prop: 'setting1',
other: 'other',
},
{
prop: 'setting2',
},
];
const user: Record<string, string>[] = [
{
prop: 'new',
other: 'something',
},
];
const result = ESLintUtils.applyDefault(defaults, user);
expect(result).toStrictEqual([
{
prop: 'new',
other: 'something',
},
{
prop: 'setting2',
},
]);
expect(result).not.toBe(defaults);
expect(result).not.toBe(user);
});
it('returns a brand new array', () => {
const defaults: undefined[] = [];
const user: undefined[] = [];
const result = ESLintUtils.applyDefault(defaults, user);
expect(result).not.toBe(defaults);
expect(result).not.toBe(user);
});
it('should work with array of options', () => {
const defaults: unknown[] = ['1tbs'];
const user: unknown[] = ['2tbs'];
const result = ESLintUtils.applyDefault(defaults, user);
expect(result).toStrictEqual(['2tbs']);
expect(result).not.toBe(defaults);
expect(result).not.toBe(user);
});
it('should work when default option is null', () => {
const defaults: unknown[] = [null];
const user: unknown[] = [
{
prop: 'setting1',
other: 'other',
},
];
const result = ESLintUtils.applyDefault(defaults, user);
expect(result).toStrictEqual(user);
expect(result).not.toBe(defaults);
expect(result).not.toBe(user);
});
});