store icon indicating copy to clipboard operation
store copied to clipboard

getSelectorStub doesn't work for function selectors created by one factory function

Open Dosant opened this issue 7 years ago • 0 comments

This is a...

  • [ ] feature request
  • [x] bug report
  • [ ] usage question

What toolchain are you using for transpilation/bundling?

  • [x] angular/cli
  • [ ] Custom @ngTools/webpack
  • [ ] Raw ngc
  • [ ] SystemJS
  • [ ] Rollup
  • [ ] Other

Environment

NodeJS Version: 8.9.1 Typescript Version: 2.7.2 Angular Version: 6.0.0 @angular-redux/store version: 9.0.0 @angular/cli version: (if applicable): 6.0.0 OS: macOS 10.13.1

Expected Behaviour:

MockNgRedux.getSelectorStub(functionSelector) should properly stub any function selector.

Actual Behaviour:

If 2 function selectors were created by one factory function selectors, then the 2nd stub will override previous stub.

Additional Notes:

This is pretty common scenario to use a selector factory, in my case I am using reselect.

As I understand, the bug happens due to this line: https://github.com/angular-redux/store/blob/master/testing/observable-store.mock.ts#L85.

When selectors are produced by one factory function, we can't compare them using function.toString() method.

Here is the reproduction of a problem's root cause: https://jsfiddle.net/34d76j1y/5/

I guess possible solution would be to use a WeakMap as a cache for selector stubs?

Dosant avatar Jun 21 '18 12:06 Dosant