Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Feature Request: Angular v14 "inject" support #4282

Closed
ssergdev opened this issue Nov 17, 2022 · 5 comments · Fixed by #4306
Closed

Feature Request: Angular v14 "inject" support #4282

ssergdev opened this issue Nov 17, 2022 · 5 comments · Fixed by #4306
Assignees
Labels

Comments

@ssergdev
Copy link

Describe the feature or problem you'd like to solve

MockBuilder is mocking the providers defined in the component constructor but ignoring the providers defined with "inject" method:

@Injectable({providedIn: 'root'})
export class MyService{ ... }

@Component(...)
export class MyComponent{
  myService = inject(MyService)
}

describe('MyComponent', () => {
  beforeEach(() => MockBuilder(MyComponent, MyModule))

  it('should create', () => {
    const fixture = MockRender(MyComponent);
    const component = fixture.point.componentInstance;
    expect(component).toBeDefined();
  });
})

The way how I can mock MyService here is to define it as a context:

  beforeEach(() => MockBuilder(MyComponent, [MyModule, MyService])

Background

    "ng-mocks": "14.3.3",
    "@angular/core": "14.0.4"
@satanTime
Copy link
Member

Hi @ssergdev,

thanks for reporting the issue.

Could you check that this build works are you expect? ng-mocks.zip

@ssergdev
Copy link
Author

ssergdev commented Nov 20, 2022

Hello and thank you for replying so fast! Quick test fails, tomorrow will reproduce in a separate repo.

@satanTime
Copy link
Member

Hi, thanks for checking.

I added some improvements: ng-mocks.zip

satanTime added a commit that referenced this issue Nov 26, 2022
feat(MockBuilder): mocks root providers via inject function #4282
@satanTime
Copy link
Member

v14.4.0 has been released and contains a fix for the issue. Feel free to reopen the issue or to submit a new one if you meet any problems.

@Francesco-Borzi
Copy link

@satanTime This bug seems to happen again on ng-mocks 14.13.0

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants