1.1.3 • Published 3 years ago

redux-test-saga v1.1.3

Weekly downloads
137
License
MIT
Repository
github
Last release
3 years ago

redux-test-saga

Easy redux saga testing with jest

Installation

npm install --save-dev redux-test-saga

or

yarn add --dev redux-test-saga

Usage example

export function* fetchWossnamesSaga(action: Action) {
    yield put(fetchWossnamesStart())

    try {
        const { success, error, wossnames } = yield call(fetchWossnames)
        if (success) {
            yield put(fetchWossnamesSuccess(wossnames))
        } else {
            yield put(fetchWossnamesFailure(error))
        }
    } catch (e) {
        yield put(fetchWossnamesFailure(e.message))
    }
}
import { testSaga } from 'redux-test-saga'
import { fetchWossnames } from './actions'
//etc.

describe('fetchWossnameSaga', () => {
    it('handles happy path', () => {
        const wossnames = [{ foo: 'bar' }]

        testSaga(fetchWossnamesSaga, fetchWossnames())
            .put(fetchWossnamesStart())
            .call(fetchWossnames)
            .result({ success: true, wossnames })
            .put(fetchWossnamesSuccess(wossnames))
            .done()
    })

    it('handles unexpeced errors', () => {
        testSaga(fetchWossnamesSaga, fetchWossnames())
            .put(fetchWossnamesStart())
            .call(fetchWossnames)
            .throw(new Error('Oh no'))
            .put(fetchWossnamesFailure('Oh no'))
            .done()
    })
})
1.1.3

3 years ago

1.1.1

3 years ago

1.1.2

3 years ago

1.1.0

4 years ago

1.0.2

4 years ago

1.0.3

4 years ago

1.0.1

4 years ago

1.0.0

4 years ago

1.0.0-alpha.6

4 years ago

1.0.0-alpha.5

4 years ago

1.0.0-alpha.4

4 years ago

1.0.0-alpha.3

4 years ago

1.0.0-alpha.2

4 years ago

1.0.0-alpha.1

4 years ago