-
Notifications
You must be signed in to change notification settings - Fork 20
/
Copy pathobserve.spec.js
55 lines (48 loc) · 1.5 KB
/
observe.spec.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
const observe = require('../src/observe');
require('./setup');
const object = {
prop: true,
sub: {
subsub: {
bla: true,
},
},
};
describe('observe', () => {
it('should notify on reading property', () => {
const spy = sinon.spy();
const proxy = observe(object, spy);
const temp = proxy.prop; // eslint-disable-line no-unused-vars
expect(spy.calledWith('prop')).to.be.equal(true);
});
it('should notify on writing property', () => {
const spy = sinon.spy();
const proxy = observe(object, spy);
proxy.prop = false;
expect(spy.calledWith('prop')).to.be.equal(true);
});
it('should notify on deleting property', () => {
const spy = sinon.spy();
const proxy = observe(object, spy);
delete proxy.prop;
expect(spy.calledWith('prop')).to.be.equal(true);
});
it('should notify on reading sub-property', () => {
const spy = sinon.spy();
const proxy = observe(object, spy);
const temp = proxy.sub.subsub.bla; // eslint-disable-line no-unused-vars
expect(spy.calledWith('sub')).to.be.equal(true);
});
it('should notify on writing sub-property', () => {
const spy = sinon.spy();
const proxy = observe(object, spy);
proxy.sub.subsub.bla = false;
expect(spy.calledWith('sub')).to.be.equal(true);
});
it('should notify on deleting sub-property', () => {
const spy = sinon.spy();
const proxy = observe(object, spy);
delete proxy.sub.subsub.bla;
expect(spy.calledWith('sub')).to.be.equal(true);
});
});