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