You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
HttpClient testing guide suggests using deprecated TestBed.get invocation on abstract class HttpTestingController #30750
This is deprecated from v8.0.0 (because the HttpTestingController is an abstract class), and therefore throws a warning in the linter; the docs should be updated to use (or at least show an example of) the recommended, compliant code.
Add the minimal HttpClient testing example from the documentation:
describe('HttpClient testing',()=>{lethttpClient: HttpClient;lethttpTestingController: HttpTestingController;beforeEach(()=>{TestBed.configureTestingModule({imports: [HttpClientTestingModule]});// Inject the http service and test controller for each testhttpClient=TestBed.get(HttpClient);httpTestingController=TestBed.get(HttpTestingController);});/// Tests begin ///});
Run the linter:
$ ng lint
Linting "demo"...
...
WARNING: /path/to/app/service.test.ts:16:41 - get is deprecated: from v8.0.0 use Type<T> or InjectionToken<T>
Lint warnings found in the listed files.
Expected vs Actual Behavior**
Expected: docs example uses up-to-date code
Actual: docs example uses deprecated code, leading to a warning
📷Screenshot
🔥 Exception or Error
WARNING: /path/to/app/service.test.ts:16:41 - get is deprecated: from v8.0.0 use Type or InjectionToken
@trotyl I wasn't sure whether it would be a duplicate or not - it's not clear to me from the other issue whether TestBed.get(HttpTestingController) is still going to be the right way to get the controller, or whether the method will require additional type information. At the very least, I'd like to track here that the docs get some kind of update in the interim.
Activity
trotyl commentedon May 30, 2019
Duplicate of #29905
Note: the deprecation is not ideal and has been temporarily
reverteddisabled.textbook commentedon May 30, 2019
@trotyl I wasn't sure whether it would be a duplicate or not - it's not clear to me from the other issue whether
TestBed.get(HttpTestingController)is still going to be the right way to get the controller, or whether the method will require additional type information. At the very least, I'd like to track here that the docs get some kind of update in the interim.trotyl commentedon May 30, 2019
It is the right way, any class is valid injection token, previously discussed a lot at #25222 and #26491.
textbook commentedon May 30, 2019
@trotyl cool, thanks for the info
angular-automatic-lock-bot commentedon Sep 15, 2019
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.