MockStore mock selectors created with overrideSelector do not emit on the stream when .setResult is called
This is essential functionality for testing long-lived streams, e.g. | async streams, and replacing Store in component tests
If another approach is preferred, it needs to be indicated in the documentation
https://github.com/pburkindine/ngrx-mockstore-setresult
ng test to see the third test in src/app/sample-component/sample-component.component.spec.ts failsAngular: 8
NgRx: 8
Node: 10
OS: OSX High Sierra
[ ] Yes (Assistance is provided if you need help submitting a pull request)
[X] No
@pburkindine I don't see the sample-component folder in the linked repo.
@jtcrowson D'oh! Try again please :D
To trigger a state change, you must set a new store result.
AFAIK we can't do this for you because a selector is just a pure function:
it('should updata the message', () => {
fixture.detectChanges();
expect(fixture.nativeElement.innerHTML.includes('one')).toBeTruthy();
actions.getMessage.setResult('two two');
store.setState({});
fixture.detectChanges();
expect(fixture.nativeElement.innerHTML.includes('two two')).toBeTruthy();
});
I'm sorry, but I don't know why this was closed. Tests included in the repo by @pburkindine still don't pass, even after setting new state, as described by @timdeschryver. I'm having exactly same issue with my unit tests in my projects.
The suggestion shown by @timdeschryver works for me. Make sure to call store.setState() and fixture.detectChanges().
Hey @brianguppy, also checkout refreshState(), added in #2148 with documentation for it in #2182.
Most helpful comment
Hey @brianguppy, also checkout
refreshState(), added in #2148 with documentation for it in #2182.