Angular jasmine unit test error with 'and' on a spy

Viewed 1600

Can anyone shed some light on this error I'm seeing in my Jasmine unit tests where I'm creating a spy on a mock service call and trying to return a value?

This is an example of the spy:

mockService = jasmine.createSpyObj('MyService', ['getSomeId']);
mockService.getSomeId.and.returnValue(10);

When i run ng test, the following error shows up in the console window - but the test actually passes successfully in the browser:

error TS2339: Property 'and' does not exist on type '() => string'. src/app/services/myservice.service.spec.ts(57,45): error TS2339: Property 'and' does not exist on type '(controller: string) => string'.

Any ideas?

1 Answers

Alex shed some light on the issue - I was strongly typing the mock service as the service type, instead of a spy type. Once I removed the type, the error went away.

Related