lundi 25 juillet 2016

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

I'm working on a Angular2 / TypeScript Project and using jasmine for unit-testing.

How to test a function which is called with a constant using jasmine. Eg. 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 () {
  it('should call drawCircle method with parameters'){
    expect( logo.drawCircle ).toHaveBeenCalledWith( 10, 10, 10 ); //This fails
  }
}

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

Aucun commentaire:

Enregistrer un commentaire