typedefinition: TestBed.inject(T) should return jasmine.SpyObj<T>
See original GitHub issueπ bug report
Affected Package
The issue is caused by package @angular/....@angular/core testing
I was playing with the test project of Angular and I noticed that the TestBed.inject(service) method is returning the service
whereas it should be returning a jasmine.SpyObj<service>
Can you check the type definition of the method please or maybe I misunderstood the definition?
Issue Analytics
- State:
- Created 4 years ago
- Reactions:2
- Comments:12 (5 by maintainers)
Top Results From Across the Web
Angular TestBed.inject type error when injecting into a spy
Seems to be bad function typing by Angular, as the .inject() returns T and not SpyObj<T> . But thank you for the valid...
Read more >Testing Dependency Injection β’ Angular - codecraft.tv
When the component is created since it has its own injector it will resolve the AuthService itself and not forward the request to...
Read more >8. Mocking the injected service using createSpyObj method ...
In this video we will see how to mock the injected service using jasmine.createSpyObj method and spy on the mocked service methodΒ ...
Read more >28. Create instance for the Services using Test Bed inject ...
In this video we will see how to create instance for the services using the Test Bed Inject Method - Angular Unit Testing....
Read more >https://raw.githubusercontent.com/ngneat/spectator...
Changelog All notable changes to this project will be documented in this file. ... spectator - This method taps into the type safe...
Read more >
Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free
Top Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Iβm trying to do something similar to the code in the test project and Iβm getting a compiler error when I try to assign
TestBed.inject(ValueService)
tovalueServiceSpy
. And it really should be a compiler error. The only reason the StackBlitz demo works is because the compiler canβt find a definition forjasmine.SpyObj
, so it sets the type ofvalueServiceSpy
toany
and then allows the assignment. Unless Iβm missing some sort of compiler flag in my project that adds logic to the compiler to add additional type info toTestBed.inject()
after aTestBed.configureTestingModule()
, the code in the demo project wonβt compile in a normal environment.This issue has been automatically locked due to inactivity. Please file a new issue if you are encountering a similar or related problem.
Read more about our automatic conversation locking policy.
This action has been performed automatically by a bot.