forked from mozilla/web-ext
-
Notifications
You must be signed in to change notification settings - Fork 0
/
test.expand-prefs.js
62 lines (53 loc) · 1.36 KB
/
test.expand-prefs.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
import { assert, expect } from 'chai';
import { describe, it } from 'mocha';
import expandPrefs from '../../../src/util/expand-prefs.js';
describe('utils/expand-prefs', () => {
it('expands dot-deliminated preferences into a deep object', () => {
const input = {
a: 'a',
'b.c': 'c',
};
const expected = {
a: 'a',
b: {
c: 'c',
},
};
const actual = expandPrefs(input);
assert.deepEqual(actual, expected);
});
it("doesn't pollute the object prototype", () => {
const call = 'overriden';
const input = {
'hasOwnProperty.call': call,
};
const expected = {
hasOwnProperty: {
call,
},
};
const actual = expandPrefs(input);
assert.notEqual(Object.prototype.hasOwnProperty.call, call);
assert.deepEqual(actual, expected);
});
it('throws an error when setting the child property of an already set parent', () => {
const input = {
a: 'a',
'a.b': 'b',
};
expect(() => expandPrefs(input)).to.throw(
'Cannot set a.b because a value already exists at a',
);
});
it('allows overriding a parent even if a child has already been set', () => {
const input = {
'a.b': 'b',
a: 'a',
};
const expected = {
a: 'a',
};
const actual = expandPrefs(input);
assert.deepEqual(actual, expected);
});
});