Redux 액션이 있습니다.이 액션은 두 가지 다른 액션을 전달합니다. 각 동작은 가져온 기능에서 검색됩니다. 하나는 로컬 모듈에서, 다른 하나는 외부 라이브러리에서 가져옵니다. 내 테스트에서Sinon을 사용하여 함수를 스텁 할 수 없습니다.
import { functionA } from './moduleA';
import { functionB } from 'libraryB';
export function myAction() {
return (dispatch) => {
dispatch(functionA());
...
dispatch(functionB());
}
}
가 나는 기능을 스텁하기 위해 sinon
샌드 박스를 사용하고 있습니다 만 테스트의 두 전달합니다. 나는 3 명이 모두지나 가기를 기대하고있다. 마지막 기대
import * as A from './moduleA';
import * as B from 'libraryB';
describe(__filename, async() => {
it('Calls 2 other actions',() => {
sandbox = sinon.sandbox.create();
const dispatch = sandbox.stub();
sandbox.stub(A, 'functionA');
sandbox.stub(B, 'functionB');
await myAction()(dispatch);
// passes
expect(dispatch.callCount).to.equal(2);
//passes
expect(A.functionA).to.have.been.called();
// fails
expect(B.functionB).to.have.been.called();
});
});
오류와 함께 실패합니다
TypeError: [Function: functionB] is not a spy or a call to a spy!
언제 출력 바벨이 보낸 수출 를 가져 오는 방법과 관련이있을 것으로 보인다 나는이 얻을 콘솔에 기능 (ES6 re-exported values are wrapped into Getter). 이 기능은 테스트가 아닌 라이브로 작동합니다.
{ functionA: [Function: functionA] }
{ functionB: [Getter] }
나는 stub.get(getterFn)
를 사용하여 시도했지만 그것은 단지 나에게 오류 제공 :
TypeError: Cannot redefine property: fetchTopicAnnotations
답장을 보내 주셔서 감사합니다.하지만 스텁의 이름을 지정해도 아무런 효과가 없습니다. –