-2

I have to write unit test case for the below code in a function inside ts file

logout() {
this.cookieService.delete('deleted_cookie_name');
}

I have writtern like this using spy.

cookieService=jasmine.createSpyObj(['delete'])
uranus1212
  • 63
  • 1
  • 5

1 Answers1

3

I would have done something like below;

it('should delete cookie name', inject([CookieService], (cookieService: CookieService) => {
const serviceSpy = spyOn(cookieService, 'delete');
component.logout();
expect(serviceSpy).toHaveBeenCalled();
}
))
ammadkh
  • 569
  • 3
  • 9