angular-redux / store

Angular 2+ bindings for Redux
MIT License
1.34k stars 205 forks source link

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

Open Dosant opened 6 years ago

Dosant commented 6 years ago

This is a...

What toolchain are you using for transpilation/bundling?

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?