-
Notifications
You must be signed in to change notification settings - Fork 10
/
nodeJs.js
68 lines (56 loc) · 1.26 KB
/
nodeJs.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
/**
* This test suite runs outside of Jest/JSDOM to properly represent
* then Node.js environment
*/
const assert = require('assert');
const { store, afterChange } = require('../..');
// Very sophisticated test framework.
const runTest = (name, func) => {
try {
func();
} catch (err) {
throw Error(`${name}: ${err}`);
}
};
runTest('The store should work without `window` present', () => {
assert.equal(typeof window, 'undefined');
store.anObject = {
level1: {
level2: 'level 2 text',
},
};
assert.deepStrictEqual(store, {
anObject: {
level1: {
level2: 'level 2 text',
},
},
});
// Now update things in the store
store.anObject.level1.level2 = 'level 2 text!';
assert.deepStrictEqual(store, {
anObject: {
level1: {
level2: 'level 2 text!',
},
},
});
delete store.anObject;
assert.deepStrictEqual(store, {});
});
runTest('should trigger afterChange', () => {
const changes = [];
afterChange((e) => {
changes.push(e.changedProps[0]);
});
store.prop1 = {};
store.prop1.prop2 = {};
store.prop1.prop2.foo = 'bar';
store.prop1.prop2.foo = 'baz';
assert.deepStrictEqual(changes, [
'',
'prop1',
'prop1.prop2',
'prop1.prop2.foo',
]);
});