Comments (13)
I just noticed this too. Tests pass even if I pass junk into the mockStore()
init call, e.g. mockStore('asdf', done)
. Using redux-mock-store 0.0.6 with jasmine/karma and mocking XHRs with karma-jasmine-ajax.
from redux-mock-store.
I believe that this library supports Mocha instead of Jasmine and the two libraries differ on how they use the done
function. With Mocha, calling the done function with an error will fail the spec, but in Jasmine there is a special done.fail
function which needs to be called to fail the spec (see the docs for async support). For now I'm working around it by passing in the done function like this:
const store = mockStore({ }, expectedActions, (e) => {
if(e instanceof Error) {
done.fail(e);
} else {
done(e);
}
});
from redux-mock-store.
Thanks @jwbennet your explanation makes complete sense, I'll use your workaround. I don't know if @arnaudbenard is interested in also supporting Jasmine. I can maybe put together a PR, if not feel free to close this issue.
from redux-mock-store.
@jwbennet thanks for the workaround!
@jdmunro @arnaudbenard +1 for Jasmine support (or a framework-agnostic fork).
from redux-mock-store.
Is there an easy method to detect if we are using Jasmine or mocha?
If that's the case, I'm happy to support Jasmine
from redux-mock-store.
I had a pragmatic solution in mind:
if (done.fail) {
done.fail(e);
} else {
// ... current exception handling.
}
It isn't the most robust solution but it should do the trick for now. Alternatively we can just look for the presence of the jasmine
variable.
from redux-mock-store.
I think the greater issue here is how redux-mock-store bypasses my assertion library. I've put a fair amount of time into integrating redux-mock-store into my tests, and I now feel strongly that this is an anti-pattern that will probably bite a lot of folks.
A mocking lib should not handle setting expectations. It should simply provide an interface that helps devs run isolated test scenarios. A mocking lib shouldn't need to support any test framework - it's probably fair to say the issue of supporting mocha vs jasmine is an xy problem.
For now I'll be using spies when I need to mock around stores, but I do love the idea of using a lib like this - it just needs less responsibility. I guess we'll see if the guy who's actually doing something about this for the community agrees :)
At any rate, thanks for your work, mate.
from redux-mock-store.
I agree with @erquhart. The library should be framework agnostic. I have noticed that other people had problems with Jasmine and tape as well. I am not sure how to handle that yet. Do you have examples of libraries that have the same type of API?
from redux-mock-store.
I've commented on #22.
from redux-mock-store.
Thanks for the workaround @jwbennet
from redux-mock-store.
In the meantime, here's a temporary module for Jasmine (and Mocha): https://www.npmjs.com/package/redux-mock-store-jasmine
from redux-mock-store.
There's a new version out, please give it a try 👊
from redux-mock-store.
Excellent, thanks @arnaudbenard
from redux-mock-store.
Related Issues (20)
- [NPM] - ES Modules are not released on 1.5.3 HOT 3
- This repo still alive? HOT 13
- Actions dispatched after using Promise.all don't save to store HOT 2
- Configuring store for all React tests HOT 1
- Cannot read property 'enqueueForceUpdate' of undefined
- Docs link is not working the NPM repo HOT 3
- Testing nested actions HOT 2
- Test with extra dispatched action in middleware
- update url's in package.json to point to latest location HOT 2
- What is in 1.5.4? HOT 1
- Issue with Store Helpers HOT 1
- The Documentation is wrong for CommonJS HOT 1
- does not work with nested async thunks? HOT 4
- Version 1.5.4? HOT 5
- [Redux-toolkit] [createEntityAdapter] Cannot read property 'ids' of undefined HOT 1
- getActions method doesn't log correct actions
- Usage with createAsyncThunk - 'await' has no effect on the type of this expression. HOT 1
- clearActions method isn't working as expected
- ESM problem with default export
- Add note that this is no longer recommended or maintained?
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
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.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from redux-mock-store.