Closed dasniko closed 8 years ago
Hi,
If you will try to assert empty object - you will get exception from redux-mock-store
(see this PR https://github.com/arnaudbenard/redux-mock-store/pull/40)
expect(myAction()).toDispatchActions([]);
- this line should not throw any error by design.
Regarding the question about actions comparison - we are using the deep comparison. So if payload is different - actions are considered as different, and assertions should be failed.
Just in case if we have a bug - can you please provide an example with actions and tests, so we will be able to reproduce a problem?
Thanks for your quick reply!
I'll provide an example, hopefully over the weekend!
Ok, I just have already found some time to reproduce the behaviour.
Look at this repo: https://github.com/dasniko/redux-test-issue
Install it with npm install
and then run the tests with npm test
.
The test suite contains two scenarios, first with your lib, second is conventional. Both should fail, but first test case succeeds, second fails as expected.
It's totally ok if the error is on my side, but I don't see it. But perhaps it's a bug.
Since you are working in with async flows, you should provide done
as a second argument of toDispatchActions.
it('should fail, because objects are different', (done) => {
const expectedActions = [
{type: types.RESOURCES_REQUEST},
{type: types.RESOURCES_RECEIVE, payload: {bar: 'foo'}}
];
expect(actions.fetchResources()).toDispatchActions(expectedActions, done);
});
Ah, let me check how it should be done by using return promise
statements (I haven't tested this feature)
Well, right now we are not returning promise from toDispatchActions(expectedActions, done)
. But if you think that is will be useful - we can create a feature request for that.
We are using expect(actions.fetchResources()).toDispatchActions(expectedActions, done);
in our projects for.
Thank you very much for your help!
So, I can go with the done
option, that's ok for me.
Because of redux-things/redux-actions-assertions-js#2 now possible to use next syntax:
it('<test name>',()=>{
return expect(fetchData()).toDispatchActions(expectedActions).then(()=>{
expect(api.fetch).toHaveBeenCalled('/url');
});
});
Hi,
I'm using your neat library with mocha and expect and I'm facing an issue/misbehaviour, which I don't know if it's an error of your lib or my fault on using it.
When calling
expect(myAction()).toDispatchActions(expectedActions);
it seems that it doesn't matter what is inside expected Actions, as long it is an array or an object, even empty arrays or empty objects are ok and don't lead to an error. When replacing it with a string, null, undefined, etc. it's throwing an error. Also, if I have my expected actions in it and some values are not equal, the tests also pass. It's not an issue of my actions, b/c when testing it with the "old-fashioned" way with redux-mock-store, the tests will fail if values are not equal.I set up everything like described in your readme. Can you help me? Thanks, Niko