javascript - rxjs/redux observable Actions dispatched in the wrong order when running multiple tests -
i'm writing tests redux observable epics jasmine. when running 1 of tests "alone" (with fit(...)
) test passes, when running in combination test (with it(...)
) fails because actions dispatched in wrong order. appreciated!
there few epics i'm not going post them unless necessary.
this (kind of) test file:
const epicmiddleware = createepicmiddleware(combinedepics) const mockstore = configuremockstore([epicmiddleware]) describe('my test', () => { let store beforeeach(() => { store = mockstore(...) jasmine.ajax.install() }) aftereach(() => { jasmine.ajax.uninstall() epicmiddleware.replaceepic(combinedepics) }) // test 1 passes it("test 1", () => { jasmine.ajax.stubrequest("url-1").andreturn({ status: 200, responsetext: json.stringify({ ... }) }) store.dispatch(initializepage()) expect(store.getactions()).toequal([ { type: initialize_page }, { type: my_action1 }, { type: initialized_page } ]) }) // test 2 passes `fit` not `it` it("test 2", () => { jasmine.ajax.stubrequest("url-2").andreturn({ status: 200, responsetext: json.stringify({ ... }) }) store.dispatch(initializepage()) expect(store.getactions()).toequal([ { type: initialize_page }, { type: my_action2 }, { type: initialized_page } ]) /** * `fit` actions come in order [initialize_page, my_action2, initialized_page] * `it` actions come in order [initialize_page, initialized_page, my_action2] */ }) })
turns out works if create epicmidleware
in beforeeach
instead of using epicmiddleware.replace(combinedepics)
. so:
describe('my test', () => { let store let epicmiddleware let mockstore beforeeach(() => { epicmiddleware = createepicmiddleware(combinedepics) mockstore = configuremockstore([epicmiddleware]) store = mockstore(...) jasmine.ajax.install() }) aftereach(() => { jasmine.ajax.uninstall() }) ...
Comments
Post a Comment