S
S
Sergey Suntsev2019-11-21 11:20:55
JavaScript
Sergey Suntsev, 2019-11-21 11:20:55

Why, when testing sagas, there are errors of lack of data in the sagas themselves?

There is a saga

export const getQueryUserSaga = function * () {
  while (true) {
    let {payload} = yield take(GET_QUERY_USERS_REQUEST)
   
    const filtersAll = yield select(filtersSelector)

    let filters = null
    filtersAll.filter(i => Object.getOwnPropertyNames(i)[0] === moduleName).map(item => filters = item[moduleName])
  ...

 And test
describe('users sagas', () => {
  
  test('look on a default offset users at list', () => {
    const sagaGetUsers = getQueryUserSaga()
    
    expect(sagaGetUsers.next().value).toEqual(take(GET_QUERY_USERS_REQUEST))
    expect(sagaGetUsers.next().value).toEqual(select(filtersSelector))  
  })
})

Why do I get an error TypeError: Cannot read property 'payload' of undefined testing sagas
when running the test

Answer the question

In order to leave comments, you need to log in

1 answer(s)
S
Sergey Suntsev, 2019-11-21
@GreyCrew

Found the answer.
You need to define payload and send the value as a parameter to, sagaGetUsers.next()
for example

describe('users sagas', () => {
  
  test('look on a default offset users at list', () => {
    const sagaGetUsers = getQueryUserSaga()
    const payload = 'default_filter=none'
    expect(sagaGetUsers.next(payload).value).toEqual(take(GET_QUERY_USERS_REQUEST))
    expect(sagaGetUsers.next().value).toEqual(select(filtersSelector))  
  })
})

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question