Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Angular test cannot access Service before initialization

I cannot make tests start, because they fail at the very beginning with error

Chrome 83.0.4103.61 (Linux x86_64) ERROR
  An error was thrown in afterAll
  Uncaught ReferenceError: Cannot access 'SomeService' before initialization
  ReferenceError: Cannot access 'SomeService' before initialization

... stack trace

The thing is:

a) It's a singleton service and providedIn: 'root'

b) Stack trace points to nowhere (it even includes test files which are totally commented out so there is no single line of code.

c) Other tests don't start because of that

d) I can't start disabling tests to find the starting point due to their amount.

How do I find where an error could happen and what could cause this? Can it be connected to updating Karma, Jasmine and spec reporters to the latest versions of their packages? I'm working with Angular 9

like image 239
Sergey Avatar asked Jun 21 '26 19:06

Sergey


1 Answers

It appears that it's due to project's "age". It was started with Angular 6. According to this comment emitDecoratorMetadata in the config is the cause. After deleting this everything works fine...

like image 165
Sergey Avatar answered Jun 23 '26 12:06

Sergey



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!