How do you test a function that is called with a constant using jasmine + TypeScript

I am working on an Angular2 / TypeScript project and using jasmine for unit testing.

How to check a function that is called with a constant using jasmine. For instance. 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 } } 

Is there any other way to check other than passing a constant as a parameter to the toHaveBeenCalledWith method?

+6
source share
2 answers

you need to use the spy first

 spyOn('logo','drawCircle'); logo.drawLogo(); expect( logo.drawCircle ).toHaveBeenCalledWith( 10, 10, 10 ); 
0
source

import the RADIUS into your spec file and then

 expect( logo.drawCircle ).toHaveBeenCalledWith( RADIUS, RADIUS, RADIUS ); 
0
source

All Articles