0

I am trying to write a unit test for a simple saga code snippet. Whenever I run any test I just get a message saying 'cannot read property 'param' of undefined.

const { param } = yield take(action.FETCH_ACTION)

I expect this is because the param is not getting assigned through whatever test I write.

An example of how I am trying to test this is:

expect(generator.next().value).toEqual(take(actions.FETCH_ACTION))

This was working fine for me before I added this parameter in my action creator. But now that I am trying to use this parameter I need to include it in the rest of my tests.

How can I write a unit test that can correctly assign this param value and use it in upcoming tests?

1 Answer 1

0

If you want to send a value to your generator you need to pass it via .next(val). E.g.

expect(generator.next({param: testParam}).value).toEqual(take(actions.FETCH_ACTION))

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.