We’re start using Aurelia’s Store for State Management. It’s pretty straightforward, we have no issues dispatching /listening to State changes whatsoever.
My problem is Unit Testing, we’re using Jasmine/Karma and I can’t get notified after I dispatch something.
My container is something like this:
@autoinject()
@connectTo<IWhatIfState>({
selector: {
bSelectedScenario: store => store.state.pipe(pluck("selectedScenario"), distinctUntilChanged()),
},
})
export class WhatIfContentHeader {
...
and my unit test goes like:
it("Saves the job edition - saveEditSection()", async () => {
...
//this sets a list of Scenarios into the State - it works
await sut.store.dispatch(fetchViewModelAction.name, 1, 1);
//this also works, it finds my scenario that was previously set on State (method above)
await sut.store.dispatch(setSelectedScenarioAction.name, 1);
//at this point I should be able to use bSelectedScenario, but inside saveEditSection it is undefined
await sut.saveEditSection();
});
FYI: my setSelectedScenarioAction method does the job correctly, the reducer returns the state with selectedScenario
It really seems like the @connectTo() is not working (being notified)
most likely a left-over. If you prepend describe/it with f it will force only those to execute. Likewise if you prepend it with x (xit/xdescribe) it will skip these on the execution
One more thing with regards to the actual test. There is a helper method callled executeSteps which can be awaited and takes a store plus n steps. Each one is a function which gets the resulting state so you can expect things with it and dispatch the next action. Take a look at the unit tests of the Store plugin itself for an example