I am writing mocha tests against a Reflux store, to validate that an action causes the state within a store to change. The scaled-down version of the code is given below:
Store:
var AppStore = Reflux.createStore({
init: function () {
this.foo = false;
},
listenables: [AppActions],
onFooAction: function() {
this.foo = !this.foo;
this.trigger({action: "foo-ed"});
};
});
Action:
var AppActions = Reflux.createActions([
"fooAction"
]);
Test:
it("toggles foo", function () {
expect(AppStore.foo).to.equal(false);
AppStore.listenables[0].fooAction();
expect(AppStore.foo).to.equal(true);
});
However, the second assertion (expect(AppStore.foo).to.equal(true);
) fails saying that foo
is still false.
By performing a console.log
within the onFooAction
method, I've verified that the method is actually triggered and this.foo
is getting toggled.
Is there anything fundamental that I am missing here: conceptually or otherwise? I sincerely hope that it is not a timing issue!