Skip to content

Bug: Angular 14+ using the inject with defaultMock is not working #5073

Answered by satanTime
KevinBonnoron asked this question in Q&A
Discussion options

You must be logged in to vote

Hi there,

you are very close.

Because ENVIRONMENT_TOKEN is a dependency, it should be provided in MockBuilder:

beforeAll(() => MockBuilder(AppComponent, [ENVIRONMENT_TOKEN]));

Otherwise ng-mocks cannot detect it, because of inject it's a runtime dependency, whereas before with @Inject it was a declaration dependency, which could be detected without executing code.

The correct version of your test: https://codesandbox.io/s/silly-wescoff-xkg4ri?file=/src/test.spec.ts:641-658

Replies: 1 comment

Comment options

You must be logged in to vote
0 replies
Answer selected by satanTime
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
bug Something isn't working
2 participants
Converted from issue

This discussion was converted from issue #4973 on March 05, 2023 13:54.