Skip to content

Testing composite sagas with no direct action triggers #76

@vishnusankaran-plivo

Description

@vishnusankaran-plivo

For composite sagas with no direct action triggers, but only generator yield calls, how do we mock those yield calls with redux-saga-tester?

function* onFetchBooks(action) {
  const { genre = '', page = 1 } = action.payload
  const updatedAction = { ...action, payload: { name: searchText, page, page_size: 20 } }

  if (genre === 'Fiction') {
    yield fetchFiction(action.payload)
  } else if (genre === 'NonFiction') {
    yield fetchNonFiction(action.payload)
  } else {
    yield fetchAll(action.payload)
  }
}

*Note: onFetchBooks, fetchFiction, fetchNonFiction and fetchAll are in the same file

Mocking with jest also doesn't seems to work.

jest.fn(fetchFiction)
jest.fn(fetchNonFiction)
jest.fn(fetchAll)

Also, there isn't a way to mock in the SagaTester constructor or the .start() method as well.
Screenshot 2023-02-21 at 10 00 07 AM

Can someone help with this query?

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions