1.0.5 • Published 6 years ago

@mt-testutils/test-saga v1.0.5

Weekly downloads
1
License
MIT
Repository
-
Last release
6 years ago

test-saga

Allows easy testing of redux-sagas without having to mock anything.

Installation

npm install --save-dev @mt-testutils/test-saga

Usage

Let's assume we have a generator function like this:

function* mySaga() {
    try {
        const value1 = put(someAction);
        yield value1;
    } catch (e) {
        yield 'ERROR';
    }
}

With this helper function, we can easily test the generator, by writing one it test per yield expression:

import mySaga from './mySaga';
import testSaga from '@mt-testutils/test-saga';

testSaga(mySaga(), () => {
    it('should yield a put', nextYield => {
        nextYield.should.equal(put(someAction));
        return 'hello world'
    });
    it ('should yield the return value from last yield', nextYield => {
        nextYield.should.equal('hello world');
        return new Error('ERROR');
    });
    it ('should yield the error thrown by last yield', nextYield => {
        nextYield.should.equal('ERROR');
    });
});

Change Log

Contribution Guidelines

License

MIT licensed

Copyright © 2018 mobile.de GmbH