Comments (4)
Update: this definitely seems to be a tricky race condition kind of thing, because inserting a brief delay allows the tests to pass.
Here's an updated sandbox https://codesandbox.io/s/nifty-hofstadter-wnouo
And I'll put the updated passing code here as well for posterity:
import configureStore from "redux-mock-store";
import thunk from "redux-thunk";
const middlewares = [thunk]; // add your middlewares like `redux-thunk`
const mockStore = configureStore(middlewares);
// You would import the action from your codebase in a real scenario
function success() {
return {
type: "FETCH_DATA_SUCCESS"
};
}
function success_innerAsync() {
return {
type: "FETCH_DATA_SUCCESS--INNER_DISPATCH"
};
}
function fetchData() {
return async dispatch => {
await fetch("/users.json"); // Some async action with promise
dispatch(success());
dispatch(fetchMoreData_innerAsync());
};
}
function fetchMoreData_innerAsync() {
return async dispatch => {
await fetch("/more-data.json"); // Some async action with promise
dispatch(success_innerAsync());
};
}
async function wait(ms) {
return new Promise(resolve => {
setTimeout(resolve, ms);
});
}
it("should execute fetch data", async () => {
const store = mockStore({});
// Return the promise
await store.dispatch(fetchData());
await wait(1000);
const actions = store.getActions();
expect(actions).toEqual([success(), success_innerAsync()]);
});
from redux-mock-store.
I'm having this same issue, but the wait makes no difference for me. Redux mock store version is 1.5.4 and react-redux version is 7.1.3. Any additional async actions that are dispatched inside an action creator are never called
Edit: I actually figured out the reason that my async thunk that was dispatched inside the async action I was testing wasn't getting called because there was an exception inside it. Sadly, there's no indication of this except for when you call store.getActions(), I saw an error action that was dispatched with the error message.
from redux-mock-store.
@landonalder thanks!! I had the same error and after reading your comment about the error not showing. I search for and discovered the error. It is working now!
from redux-mock-store.
@garyee glad to hear this helped :)
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
- 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.