store get with callback tests
This commit is contained in:
parent
55654f762f
commit
58a2e80f10
|
@ -99,7 +99,6 @@ export default class Store extends EventEmitter {
|
||||||
|
|
||||||
if (opa.has(this[DATA], path)) return cb(val);
|
if (opa.has(this[DATA], path)) return cb(val);
|
||||||
|
|
||||||
// TODO: unit-test.
|
|
||||||
this.on(path, (...args) => {
|
this.on(path, (...args) => {
|
||||||
this.off(path, cb);
|
this.off(path, cb);
|
||||||
cb.apply(this, args);
|
cb.apply(this, args);
|
||||||
|
|
|
@ -36,6 +36,30 @@ export default {
|
||||||
done();
|
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) => {
|
'store - setSilent': (done) => {
|
||||||
let s = new Store();
|
let s = new Store();
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue