store get with callback tests

This commit is contained in:
Radek Stepan 2016-01-26 18:57:33 +01:00
parent 55654f762f
commit 58a2e80f10
2 changed files with 24 additions and 1 deletions

View File

@ -99,7 +99,6 @@ export default class Store extends EventEmitter {
if (opa.has(this[DATA], path)) return cb(val);
// TODO: unit-test.
this.on(path, (...args) => {
this.off(path, cb);
cb.apply(this, args);

View File

@ -36,6 +36,30 @@ export default {
done();
},
'store - get': (done) => {
let s = new Store({ 'A': [ 1, 2 ], 'B': { 'C': 3 } });
assert.equal(2, s.get('A.1')); // key as a string
assert.equal(3, s.get([ 'B', 'C' ])); // key as an array
done();
},
'store - get with callback': (done) => {
let s = new Store({ 'A': 1 });
let vals = [];
let cb = (val) => vals.push(val);
s.get('A', cb);
s.get('B', cb);
s.set('B', 2); // value provided only now
assert.deepEqual([ 1, 2 ], vals);
done();
},
'store - setSilent': (done) => {
let s = new Store();