解決できない問題に出くわします。サブモジュール メソッドをスパイしようとしましたが、moduleSpy はスパイではないというエラーが表示され、次のエラー メッセージが表示されます。モジュールは npm パッケージです。
Error: <toHaveBeenCalled> : Expected a spy, but got undefined.
import * as module from 'package';
import { TOKEN } from 'injectionToken.ts'
describe('ExampleComponent', () => {
let component: ExampleComponent;
let fixture: ComponentFixture<ExampleComponent>;
let moduleSpy;
beforeEach(async(() => {
moduleSpy = spyOn(module.sub, 'subModuleMethod');
TestBed.configureTestingModule({
declarations [ExampleComponent],
providers: [
{ provide: TOKEN, useValue: module }
]
}).compileComponents();
}));
beforeEach(() => {
fixture = TestBed.createComponent(ExampleComponent);
component = fixture.componentInstance;
});
it('test specific function call', () => {
// press button to test the sub module method
expect(moduleSpy.subModuleMethod).toHaveBeenCalled();
});
})
スパイが認識されない理由を知っている人はいますか?