Javascript Rx.Observable.fromPromise不使用Redux Observable Epics

Javascript Rx.Observable.fromPromise不使用Redux Observable Epics,javascript,unit-testing,redux,reactive-programming,redux-observable,Javascript,Unit Testing,Redux,Reactive Programming,Redux Observable,我目前正在开发一个react本机应用程序,并尝试使用redux作为中间件 为了简单起见,我只包括包含承诺的epic,而不是用网络代码冲淡它 下面是我对认证API的单元测试,该API只接受用户名、密码,并应返回用户名、密码和认证令牌。同样,这应该立即返回并使存储包含验证和验证 从“redux mock store”导入configureMockStore; 从'redux observable'导入{createEpicMiddleware}; 从“../app/services/root”导入*

我目前正在开发一个react本机应用程序,并尝试使用redux作为中间件

为了简单起见,我只包括包含承诺的epic,而不是用网络代码冲淡它

下面是我对认证API的单元测试,该API只接受用户名、密码,并应返回用户名、密码和认证令牌。同样,这应该立即返回并使存储包含
验证
验证

从“redux mock store”导入configureMockStore;
从'redux observable'导入{createEpicMiddleware};
从“../app/services/root”导入*作为servicesRoot
const-epicMiddleware=createEpicMiddleware(servicesRoot.epics);
const mockStore=configureMockStore([epicMiddleware]);
描述('会话服务',()=>{
让商店;
在每个之前(()=>{
store=mockStore();
});
之后(()=>{
replaceEpic(servicesRoot.epics)
});
描述('身份验证API',()=>{
它('我应该收到authToken',()=>{
让username='myUsername'
让password='myPassword'
const data={用户名、密码、authToken:'test_auth_token'};
让action=servicesRoot.actions.authenticate(用户名、密码)
仓库调度(行动)
expect(store.getActions()).toEqual([
servicesRoot.actions.authenticate(用户名、密码),
servicesRoot.actions.authenticate\u已完成(数据)
]);
})
})
})
我的身份验证史诗看起来像

从“rxjs”导入Rx
将*作为actionTypes从“/actionTypes”导入
从“/actions”导入{authenticate_impleted}
export const authenticatePic=操作$=>
类型(actionTypes.AUTHENTICATE)的action$
.mergeMap(操作=>
Rx.Observable.fromPromise(Promise.resolve('test'))
.map(结果=>authenticate_已完成({…action.payload,authToken:'test_auth_token'}))
)
注意:我的
servicesRoot.actions.authenticate
返回包含
authenticate
类型的要使用的操作,
authenticate\u completed
返回另一个
authenticate\u completed
操作

我的单元测试输出是

 FAIL  __tests__/api.js
  ● Session Service › Authentication API › I should receive an authToken

    expect(received).toEqual(expected)

    Expected value to equal:
      [{"payload": {"password": "myPassword", "username": "myUsername"}, "type": "AUTHENTICATE"}, {"payload": {"authToken": "test_auth_token", "password": "myPassword", "username": "myUsername"}, "type": "AUTHENTICATE_FULFILLED"}]
    Received:
      [{"payload": {"password": "myPassword", "username": "myUsername"}, "type": "AUTHENTICATE"}]

    Difference:

    - Expected
    + Received

    @@ -4,14 +4,6 @@
           "password": "myPassword",
           "username": "myUsername",
         },
         "type": "AUTHENTICATE",
       },
    -  Object {
    -    "payload": Object {
    -      "authToken": "test_auth_token",
    -      "password": "myPassword",
    -      "username": "myUsername",
    -    },
    -    "type": "AUTHENTICATE_FULFILLED",
    -  },
     ]

      at Object.<anonymous> (__tests__/api.js:36:28)

  Session Service
    Authentication API
      ✕ I should receive an authToken (44ms)

Test Suites: 1 failed, 1 total
Tests:       1 failed, 1 total
Snapshots:   0 total
Time:        1.15s
Ran all test suites matching /api/.
我不确定为什么来自承诺的
没有给出我期望的行为。我把范围缩小到一个关于承诺的问题。本质上,这是网络请求的结果,然后进行相应的处理


谢谢您的帮助。

Promise.resolve
异步解析,但您的测试会立即调用
store.getActions()
,因此您只能看到同步调度的操作。
redux模拟存储
doc中有一个关于测试的部分。