Mehul Patel
Mehul Patel

Reputation: 1194

Angular Jasmine - Argument of type 'string' is not assignable to parameter of type 'never' error in typescript

I am writing test cases in Angular using Jasmine 3.6.0 and typescript 4.1.5 with "strict": false in tsconfig.json file

I wanted to spyOn component method called 'close' and as per syntax I wrote below code

let spy = spyOn<MyComponent>(component,'close');

It was working fine but after copying source code to different folder I installed node modules and it started giving below error

'Argument of type 'string' is not assignable to parameter of type 'never''

I know this question is asked many times and I tried those solutions but I am facing same error. I don't understand what is the actual problem as my strict mode is also off.

Upvotes: 25

Views: 39040

Answers (3)

Aiza
Aiza

Reputation: 7

I encountered it now, and it happened because the method I am trying to spyOn() is with private accessibility.

You have to change it to public to be able to unit test and skip this error.

Upvotes: -2

mp3846
mp3846

Reputation: 400

let spy = spyOn<MyComponent, any>(component,'close')

Upvotes: 32

Mehul Patel
Mehul Patel

Reputation: 1194

I resolved problem

let spy = spyOn<MyComponent>(component,'close' as never)

As of now its working and not giving any errors but I don't know that is correct or not

Upvotes: 7

Related Questions