我有以下单元测试:
describe('shouldDeleteLogos', () => {
beforeEach(() => {
productService.product.project.parts['Logo'] = {
name: 'Logo'
};
productService.product.project.parts['Accent'] = {
name: 'Accent'
};
});
it(`should only call deleteLogos once if the part was provided to the method`, () => {
let part: Part = new Part();
part.name = 'Logo';
spyOn(creationSpacePSTLInstance, 'deleteLogos');
creationSpacePSTLInstance.shouldDeleteLogos(part);
expect(creationSpacePSTLInstance.deleteLogos).toHaveBeenCalledTimes(1);
});
});
然而,当我运行测试时,我收到以下错误:TypeError: undefined is not a constructor (evaluating 'expect(creationSpacePSTLInstance.deleteLogos).toHaveBeenCalledTimes(1)')
这里有什么问题?我已经监视了这个方法,我想测试它只被调用一次。根据文档,这应该是有效的。它仅适用于.toHaveBeenCalled();
,而不适用于时间参数。
以下是我正在使用的Jasmine和Karma版本。
"jasmine-core": "2.3.4"
"karma": "0.13.22",