I stumble on a problem that I cannot solve. I tried to spy on a sub-modules method but got the error that the moduleSpy is not a spy with the following error message. The module is an npm package.
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();
});
})
Does anyone have an idea why the spy is not recognized?