Giter Club home page Giter Club logo

Comments (7)

yelouafi avatar yelouafi commented on May 28, 2024 114

The best thing I can think of is trying to mock the call function to just throw an error

You don't have to mock, yield call(...) doesn't execute anything, to test the generator you provide it with dummy responses. To simulate a promise rejection, call throw on the iterator

const cart = {}
const getState = () => ({cart})
const iterator = checkout(getState)

assert.deepEqual(iterator.next().value, take(types.CHECKOUT_REQUEST))
assert.deepEqual(iterator.next(actions.checkoutRequest()).value, call(api.buyProducts, cart) )
// simulate a promise rejection
assert.deepEqual(iterator.throw('error').value, put(actions.checkoutFailure('error')))

from redux-saga.

KamuelaFranco avatar KamuelaFranco commented on May 28, 2024 16

Can this go in the docs? Please?

from redux-saga.

yelouafi avatar yelouafi commented on May 28, 2024

sorry, didnt mean to close it

from redux-saga.

rayd avatar rayd commented on May 28, 2024

Ah, awesome! Thanks so much for the quick response. That makes a lot of sense.

from redux-saga.

worc avatar worc commented on May 28, 2024

this doesn't work if you're running mocha/chai synchronously. iterator.throw('error') itself causes the error Error: the string "error" was thrown, throw an Error :)

from redux-saga.

eelfonik avatar eelfonik commented on May 28, 2024

@worc
Just use iterator.throw(new Error('error'))

from redux-saga.

worc avatar worc commented on May 28, 2024

with that e is still undefined in the catch block.

from redux-saga.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.