我偶然发现了一个我无法解决的问题。我试图监视子模块方法,但收到错误消息,即 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();
});
})
有谁知道为什么间谍不被识别?