@mt-testutils/test-saga

1.0.5 • Public • Published

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

Readme

Keywords

none

Package Sidebar

Install

npm i @mt-testutils/test-saga

Weekly Downloads

4

Version

1.0.5

License

MIT

Unpacked Size

10.2 kB

Total Files

10

Last publish

Collaborators

  • dpavicic
  • ninja.maass
  • pahund