Redux-saga: Question: Test yield call return value

Created on 27 Jul 2016  路  1Comment  路  Source: redux-saga/redux-saga

I really like how easy it is to test calls and puts, but I don't know how to test a call that has a return value.

For example, in testing this:

yield call(goToAccountDetailsLoading, action.$state, action.accountID);
const accountDetails = yield call(getAccountDetailsQuery, action.$q, action.$http, action.accountID);
yield put(put({type: ACTION_DETAILS, accountDetails}));
yield call(goToAccountDetails, action.$state);
var accountID = 0;
var gen = getAccountDetails({
    $q,
    $http,
    $state,
    accountID
});
gen.next().value.should.deep.equal(call(goToAccountDetailsLoading, $state, accountID));
gen.next().value.should.deep.equal(call(getAccountDetailsQuery, $q, $http, accountID));
gen.next().value.should.deep.equal(put(accountDetailsAction([])));
gen.next().value.should.deep.equal(call(goToAccountDetails, $state));

All my gen.next().deep.equal all pass, except for the 3rd one; the error says something like:

expected { Object (@@redux-saga/IO, PUT) } to deeply equal { Object (@@redux-saga/IO, PUT) }

They look the same which leads me to believe the deep equal is in fact deep equaling the actual call value. However, passing a mock around doesn't fix it. So I was like, hah, I'll just get the ACTUAL value by calling the function myself:

gen.next().value.should.deep.equal(call(goToAccountDetailsLoading, $state, accountID));
gen.next().value.should.deep.equal(call(getAccountDetailsQuery, $q, $http, accountID));
getAccountDetailsQuery($q, $http, accountID)
.then((results)=>
{
    gen.next().value.should.deep.equal(put(put({type: ACTION_DETAILS, accountDetails}));
    gen.next().value.should.deep.equal(call(goToAccountDetails, $state));
    done();
});
$rootScope.$digest();
$httpBackend.flush();

... however, same error. I have a feeling either I'm missing something simple, or Angular is just making this too dang fun _ahem_.

Any pointers? Thanks!

Most helpful comment

Figured it out based on your unit test example (thanks for that!), specifically line 22.

// products is your mock, w00t!
next = generator.next(products)
  t.deepEqual(next.value, put(actions.receiveProducts(products)),
    "must yield actions.receiveProducts(products)"
  )

I forgot I can pass in values to next(), so once I passed the mock in like you did, GOOD TO GO FUNKY COMADEENA!

You can close this.

>All comments

Figured it out based on your unit test example (thanks for that!), specifically line 22.

// products is your mock, w00t!
next = generator.next(products)
  t.deepEqual(next.value, put(actions.receiveProducts(products)),
    "must yield actions.receiveProducts(products)"
  )

I forgot I can pass in values to next(), so once I passed the mock in like you did, GOOD TO GO FUNKY COMADEENA!

You can close this.

Was this page helpful?
0 / 5 - 0 ratings

Related issues

stevenmusumeche picture stevenmusumeche  路  3Comments

brunobelotti picture brunobelotti  路  3Comments

mpyw picture mpyw  路  3Comments

andresmijares picture andresmijares  路  3Comments

Beingbook picture Beingbook  路  3Comments