【发布时间】:2016-11-29 15:39:35
【问题描述】:
我正在开发一个 Angular2 / TypeScript 项目并使用 jasmine 进行单元测试。
如何测试使用 jasmine 以常量调用的函数。 例如。 Logo.ts
export const RADIUS: number = 10;
export class Logo {
...
protected drawCircle( x: number, y: number, r: number ){...}
protected drawLogo(){
this.drawCircle( RADIUS, RADIUS, RADIUS );
}
...
}
Logo.spec.ts
describe('drawLogo', function () {
beforeEach(() => {
spyOn( logo, 'drawCircle');
}
it('should call drawCircle method with parameters'){
expect( logo.drawCircle ).toHaveBeenCalledWith( 10, 10, 10 ); //This fails
}
}
除了将常量作为参数传递给 toHaveBeenCalledWith 方法之外,还有其他测试方法吗?
【问题讨论】:
-
您可以使用
logo.drawCircle.calls.mostRecent().args获得更多灵活性。 -
你永远不会在你的测试中调用 drawLogo() 。那应该如何工作呢??
标签: javascript angularjs unit-testing typescript jasmine