我正在用茉莉花为redux可观察史诗写一些测试。当"单独"运行其中一个测试(使用fit(...)
(时,测试通过,但当与另一个测试(使用it(...)
(一起运行时,它会失败,因为操作以错误的顺序调度。任何帮助表示赞赏!
有一些史诗,所以除非必要,否则我不会发布它们。
这是(某种(测试文件:
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 with `fit` but not with `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 }
])
/**
* With `fit` the actions come in the order [INITIALIZE_PAGE, MY_ACTION2, INITIALIZED_PAGE]
* With `it` the actions come in the order [INITIALIZE_PAGE, INITIALIZED_PAGE, MY_ACTION2]
*/
})
})
如果我在beforeEach
中创建epicMidleware
而不是使用epicMiddleware.replace(combinedEpics)
来证明它有效。这样:
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()
})
...