相关疑难解决方法(0)

Redux-observable:史诗的开玩笑测试失败

我按照文档中的步骤来测试史诗.

...
store.dispatch({ type: FETCH_USER });

expect(store.getActions()).toEqual([
   { type: FETCH_USER },
   { type: FETCH_USER_FULFILLED, payload }
]);
...
Run Code Online (Sandbox Code Playgroud)

但是我失败了,因为后来接到了第二个动作.

Test failed
    Expected value to equal:
      [{"type": "FETCH_USER"}, {"type": "FETCH_USER_FULFILLED", "payload": [some]}]
    Received:
      [{"type": "FETCH_USER"}]

    Difference:

    - Expected
    + Received

    @@ -1,20 +1,5 @@
     Array [
       Object {"type": "FETCH_USER"},
       Object {"type": "FETCH_USER_FULFILLED", "payload": [some]} ] // this is what should be.
Run Code Online (Sandbox Code Playgroud)

所以我想我应该知道派遣何时完成或类似的事情.我怎么解决这个问题?

我使用了fetch()和Rx.Observable.fromPromise而不是ajax.getJSON()

这是我的史诗.

const fetchUserEpic = (action$) =>
  action$
    .ofType(FETCH_USER)
    .mergeMap(() => {
      return Rx.Observable.fromPromise(api.fetchUser())
        .map((users) => ({ …
Run Code Online (Sandbox Code Playgroud)

unit-testing reactjs jestjs redux-observable

1
推荐指数
1
解决办法
1874
查看次数

标签 统计

jestjs ×1

reactjs ×1

redux-observable ×1

unit-testing ×1