【发布时间】:2017-08-28 15:31:20
【问题描述】:
当我通过 jest 测试史诗时,我的测试失败了。
Test Failed
/.../node_modules/jsdom/lib/jsdom/browser/Window.js:148
return idlUtils.wrapperForImpl(idlUtils.implForWrapper(window._document)._location);
TypeError: Cannot read property '_location' of null
at Window.get location [as location] (/.../node_modules/jsdom/lib/jsdom/browser/Window.js:148:79)
at Timeout.callback [as _onTimeout] (/.../node_modules/jsdom/lib/jsdom/browser/Window.js:525:40)
at ontimeout (timers.js:380:14)
at tryOnTimeout (timers.js:244:5)
at Timer.listOnTimeout (timers.js:214:5)
这是我的一些测试。我在 fetchCategoriesEpic 中使用了 fetch() 和 promise。
it('test epic', () => {
...
const action$ = ActionsObservable.of({ type: FETCH_CATEGORIES })
fetchCategoriesEpic(action$)
.toArray() // collects everything in an array until our epic completes
.subscribe((actions) => {
expect(actions).toEqual([
{ type: FETCH_CATEGORIES },
{ type: FETCH_CATEGORIES_SUCCESS, payload: List(payload.data).map((category) => new Category(category)) }
])
})
...
}
我该如何解决这个问题?
【问题讨论】:
标签: reactjs unit-testing jestjs jsdom