Home How to test redux-thunk middleware async functions?
 I'm trying to test my asyn thunk middleware function using mocha, chai and sinon (my first time!). Please consider my files: ayncActionCreators.js export const fetchCurrentUser = () => { return (dispatch) => { setTimeout(dispatch, 100); } };  ayncActionCreators.spec.js //... it('Should work', () => { const dispatch = sinon.spy(); const action = fetchCurrentUser(); action(dispatch); expect(dispatch.called).to.be.true; });  I did not yet implement the fetchCurrentUser function - just assumed it will take some "server" time and then it will call 'dispatch()'. The spec fails, due to the async flow. If I add a setTimeout of 101 ms before the expect - it passes. My code will use some DB API that returns promise, so the async function will eventually look like: //... return (dispatch) => { return dbAPI.fetchUser().then(dispatch(....)); }  So I tried to require dbAPI and create a sinon.stub().returns(Promise.resolve()) inside the test and it didn't work as well (I thought that since the stub returns a resolved promise - the async function will act like a synchronous function). Any ideas how should I test async functions like that? Thank, Amit.