Skip to content
Advertisement

How to test selector function with redux-saga-test-plan

I am testing my redux-saga-flow, and I have an issue with testing selector method with select.

Selector

JavaScript

Redux saga flow

JavaScript

Test for flow

JavaScript

After running a test, a do not have console.log("selector"); and also this line of code did not covered by test.

How can I test a selectors?

The same does not work with unit test.

JavaScript

Advertisement

Answer

"redux-saga-test-plan": "^4.0.1".

Option 1. Use withState:

For static state, you can just use the withState method to allow select effects to work.

Option 2. Use static provider

You can provide mock values in a terse manner via static providers. Pass in an array of tuple pairs (array pairs) into the provide method. For each pair, the first element should be a matcher for matching the effect and the second effect should be the mock value you want to provide.

E.g.

saga.ts:

JavaScript

saga.test.ts:

JavaScript

Test result:

JavaScript
User contributions licensed under: CC BY-SA
8 People found this is helpful
Advertisement