Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to ignore or fix error TS2341: Property 'myFunction' is private and only accessible within class 'MyClass' with Jest 24 and Angular 8

I'm using Jest 24 with my Angular 8 app.

When a try to test a private function on a component, a TS2341 error is thrown. Something like :

error TS2341: Property 'myFunction' is private and only accessible within class 'MyClass'

Is there a way to ignore or fix that ?

I already find the "// @ts-ignore" solution, but it's so ugly !

Thanks all !

like image 563
j.2bb Avatar asked Sep 08 '25 16:09

j.2bb


1 Answers

You can cast to any, but that's ugly, too:

(MyClass as any).myFunction
like image 52
Galdor Avatar answered Sep 10 '25 06:09

Galdor