-
Notifications
You must be signed in to change notification settings - Fork 20
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
adebc4a
commit ca59678
Showing
4 changed files
with
83 additions
and
7 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -14,6 +14,7 @@ | |
"rule", | ||
"engine", | ||
"rools", | ||
"rule engine", | ||
"rules engine" | ||
], | ||
"scripts": { | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
const Delegator = require('../src/Delegator'); | ||
require('./setup'); | ||
|
||
describe('Delegator', () => { | ||
it('should delegate call', () => { | ||
const delegator = new Delegator(); | ||
const spy = sinon.spy(); | ||
delegator.set(spy); | ||
delegator.delegate('bla'); | ||
expect(spy.calledWith('bla')).to.be.equal(true); | ||
}); | ||
|
||
it('should not delegate call if unset', () => { | ||
const delegator = new Delegator(); | ||
const spy = sinon.spy(); | ||
delegator.set(spy); | ||
delegator.unset(); | ||
delegator.delegate('bla'); | ||
expect(spy.called).to.be.equal(false); | ||
}); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,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); | ||
}); | ||
}); |