1
我们有这样的功能:终极版 - 传奇单元测试意外失败
export function* postPermitApplicationRequest() {
try {
const uris = yield select(state => getUris(state));
.... (more yields hereafter)
我们测试用玩笑和柴此功能如下:
...
const action = { type: Action.POST_PERMIT_APPLICATION };
const generator = postPermitApplicationRequest(action);
it('must select uris from state',() => {
const nextCall = generator.next().value;
const uris = select(state => getUris(state));
expect(nextCall).to.deep.equal(uris);
});
然而,预期失败:
AssertionError: expected { Object (@@redux-saga/IO, SELECT) } to deeply equal { Object (@@redux-saga/IO, SELECT) }
at Assertion.assertEqual (node_modules/chai/lib/chai/core/assertions.js:485:19)
at Assertion.ctx.(anonymous function) [as equal] (node_modules/chai/lib/chai/utils/addMethod.js:41:25)
at Object.<anonymous> (src/app/pa/PermitApplicationServiceSagas.test.js:20:43)
at process._tickCallback (internal/process/next_tick.js:109:7)
这两个物体看起来像:
{ '@@redux-saga/IO': true,
SELECT: { selector: [Function], args: [] } }
但是选择器功能是不同的。一来就是generator.next()的结果中包含的代码覆盖率跳过提示:
function (state) {/* istanbul ignore next */cov_zrpq42gyn.f[12]++;cov_zrpq42gyn.s[19]++;return (/* istanbul ignore next */(0, _Selectors.getUris)(state));}
,而原来的功能不会:
function (state) {return (0, _Selectors.getUris)(state);}
它看起来像generator.next()将这些提示和断言失败
我们在这里有什么错?
我们使用终极版,传奇0.14.8
非常感谢,弗洛里安! – Erik