-
-
Notifications
You must be signed in to change notification settings - Fork 77
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
Bug: inject function can not be mocked #9397
Comments
If it helps, manually providing with Well it works in that i can mock the service but cannot use Just FYI incase it helps investigate. |
This is probably broader than auto spy (since spying doesn't necessarily have anything to do with mocking). Regardless, this behavior may be intentional. See #4973 (comment). Furthermore, you can see there's even a test ensuring the service is not mocked: https://github.com/help-me-mom/ng-mocks/blob/master/tests/issue-4282/test.spec.ts#L51-L61. This is related to issue #4282 where inject support was added. I did a little manual test and replaced @satanTime Is this intended behavior currently? If so, it may be better to label this as a |
Changed tests to use @Component(...)
export class MyComponent {
constructor(private modal: NgbModal) {} and test it('...', () => {
const ngbModal= TestBed.inject(NgbModal);
jest.spyOn(ngbModal, 'open');
...
expect(ngbModal.open).toHaveBeenCalled();
}); |
Description of the bug
The auto spy feature can not mock instance injected by
inject
function.An example of the bug
service that want be mocked:
the component:
test code:
Link:
https://github.com/wellwind/ng-mocks-inject-demo
Expected vs actual behavior
In component, when I use ctor to inject service, it works fine.
Bue when I use
inject
function, I got errors:However, it should also passed the test.
The text was updated successfully, but these errors were encountered: