Javascript 运行多个测试时,rxjs/redux可观察操作以错误的顺序调度
我正在为jasmine的redux可观察史诗写一些测试。当“单独”运行一个测试时(使用Javascript 运行多个测试时,rxjs/redux可观察操作以错误的顺序调度,javascript,jasmine,rxjs,karma-jasmine,redux-observable,Javascript,Jasmine,Rxjs,Karma Jasmine,Redux Observable,我正在为jasmine的redux可观察史诗写一些测试。当“单独”运行一个测试时(使用fit(…)),测试通过,但当与另一个测试结合运行时(使用it(…)),测试失败,因为操作的调度顺序错误。感谢您的帮助 这里有一些史诗,所以除非必要,否则我不会发布它们 这是(某种)测试文件: const epicMiddleware = createEpicMiddleware(combinedEpics) const mockStore = configureMockStore([epicMiddlewar
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]
*/
})
})
事实证明,如果我在
beforeach
中创建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()
})
...
事实证明,如果我在
beforeach
中创建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()
})
...