jeudi 29 décembre 2016

Testing throw error inside generator?

I am trying to test the thrown of an error inside a generator function as follow, using Jest and Chai:

    // function

    function * gen () {
        yield put({ type: TIME_OUT_LOGOUT })
        throw new Error('User has logged out')
    }

    //test

    let genFunc = gen()

    expect(genFunc().next).to.deep.equal(put({ type: TIME_OUT_LOGOUT }))

    expect(genFunc().next).to.throw(Error('User has logged out'));

But it isn't working. Which would be the correct way to test this?

Aucun commentaire:

Enregistrer un commentaire