It feels that there is documentation missing for a case on testing change in selector value using overridden selector.
In a given scenario below the selection from store for ready state only receives false (initial value of overridden selector), but never receives true (the updated value from setResult).
There is a small repo with reproduction of scenario: https://github.com/minijus/ngrx-set-result/blob/master/src/app/service/app.service.spec.ts
export class AppService {
constructor(private store: Store<AppState>) {}
isReady() {
return this.store
.select(selectAppReady)
.pipe(find(ready => !!ready))
.toPromise();
}
}
describe('AppService', () => {
let service: AppService;
let store: MockStore<AppState>;
let appReady: MemoizedSelector<AppState, boolean>;
beforeEach(() => {
TestBed.configureTestingModule({ providers: [provideMockStore()] });
store = TestBed.get(Store);
appReady = store.overrideSelector(selectAppReady, false);
service = TestBed.get(AppService);
});
describe('#isReady', () => {
it('should resolve once app state becomes ready', fakeAsync(() => {
setTimeout(() => {
appReady.setResult(true);
}, 1000);
const spy = jasmine.createSpy();
service.isReady().then(spy);
expect(spy).not.toHaveBeenCalled();
tick(1001);
expect(spy).toHaveBeenCalled();
}));
});
});
[x] Yes (Assistance is provided if you need help submitting a pull request)
[ ] No
More generally, setResult should cause the observable to emit. As it stands we cannot make any use of the MockStore for long-lived streams in components, for example.
More generally, setResult should cause the observable to emit. As it stands we cannot make any use of the MockStore for long-lived streams in components, for example.
Exactly, setResult could internally re-apply current state on store. Maybe by calling setState on store instance internally.
The MockStore.setState() method doesn't do anything as far as mocked selectors are concerned.
In 8.4.0 we release MockStore.refreshState() to solve this issue.
Closing in favor of #2154 (to add it to our docs)
Most helpful comment
In
8.4.0we releaseMockStore.refreshState()to solve this issue.Closing in favor of #2154 (to add it to our docs)