store: 6.4.1 breaks @select mocking
This is a…
- feature request
- bug report
- usage question
What toolchain are you using for transpilation/bundling?
- angular/cli
- Custom @ngTools/webpack
- Raw
ngc
- SystemJS
- Rollup
- Other
Environment
NodeJS Version: 6.10.2 Typescript Version: 2.3.4 Angular Version: 4.0.0 @angular-redux/store version: 6.4.1 @angular/cli version: (if applicable) 1.0.0 OS: MacOS
Link to repo showing the issus
(optional, but helps a lot)
Expected Behaviour:
Mocking Selectors and firing them should actually call all subscribers
progressStub = MockNgRedux.getSelectorStub(StateSelectors.getProgress);
progressStub.next({ steps: [], index: 0 });
Actual Behaviour:
Subscribers are not being called
export class MyComponent implements OnInit {
@select(StateSelectors.getProgress) progress$: Observable<CreateStreamProgress>;
ngOnInit() {
this.progress$.subscribe(progress => { ... }); // <-- not called
}
}
Stack Trace/Error Message:
Additional Notes:
(optional)
About this issue
- Original URL
- State: closed
- Created 7 years ago
- Comments: 36 (21 by maintainers)
Commits related to this issue
- [Fixes #413] allow tests to reset observables cached by decorators `@select` and `@select$` cache the results of their selections, in order to avoid memory leaks. However we need to be able to reset ... — committed to SethDavenport/ng2-redux by deleted user 7 years ago
- [Fixes #413] allow tests to reset observables cached by decorators `@select` and `@select$` cache the results of their selections, in order to avoid memory leaks. However we need to be able to reset ... — committed to SethDavenport/ng2-redux by deleted user 7 years ago
- Merge pull request #2 from angular-redux/master [Fixes #413] allow tests to reset observables cached by decorators (#… — committed to Collinslenjo/store by Collinslenjo 7 years ago
@ialibhay yeah that makes sense. Thanks!
I’ll try and hack up a fix tonight. We’ll need to make MockNgRedux.reset() somehow hook into all the
@select
instances… fun times.As far as I can tell, since the decorator now caches the selection (which is great for the actual app since the store shouldn’t be reset mid-usage there), the mock reset also somehow needs to tell all the decorators to clear their cached state.
Taking a look
@SethDavenport thank you for working on this and fixing. This is a great library and I am using it in earnest!
Fix PR up here: https://github.com/angular-redux/store/pull/414
@ajdaniel can you try
6.4.2-beta.0
and let me know if that fixes the issue for you? If so I’ll push out 6.4.2 officially tomorrow.@gregkopp Also note that
@select((state: AppState) => state.accountState) accountState$
will unfortunately break AoT because it can’t handle anonymous arrow functions 😦So in your case you can solve both issues by either adopting the PropertySelector approach (
@select('accountState') accountState$
) or by pulling the arrow function out, giving it a name, and exporting it (to keep AoT happy):Component:
Test:
I’ll investigate further and get back to you as soon as I can @SethDavenport. Thank you for investigating