0
オブジェクト内の参照から呼び出されている関数を監視するにはどうすればよいですか? 私はテストフレームワークとしてJasmine 2.5.2を使用し、依存関係を再配線するにはbabel-plugin-rewireを使用します。参照されたメソッドのジャスミンとバベル再配線スパイ
を見てみましょう:
a.js
import { a, __RewireAPI__ as ARewireAPI } from './a';
describe('a',() => {
describe('run',() => {
const spy= jasmine.createSpy('spy').and.callFake(() => {
...
});
beforeEach(() => {
ARewireAPI.__Rewire__('b', spy);
});
afterEach(() => {
ARewireAPI.__ResetDependency__('b');
});
it('calls b()',() => {
a.run({val: 'b'}); // doesn't call the spy because what actually being called is the reference from the map object
});
});
});