tym*_*spy 6 javascript unit-testing jasmine angularjs typescript
我正在研究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 );
}
...
}
Run Code Online (Sandbox Code Playgroud)
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
}
}
Run Code Online (Sandbox Code Playgroud)
除了将常量as参数传递给toHaveBeenCalledWith方法之外,还有其他方法可以测试吗?
你需要先使用间谍
spyOn('logo','drawCircle');
logo.drawLogo();
expect( logo.drawCircle ).toHaveBeenCalledWith( 10, 10, 10 );
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
1054 次 |
| 最近记录: |