docs(common): switch HTTP guide examples to `TestBed.inject()` (#35777)

`TestBed.get()` has been [deprecated in v9][1], in favor of
`TestBed.inject()`. In ##32382, the HTTP guide wording has been updated
to mention `TestBed.inject()` instead of `TestBed.get()`, but the
associated code snippets (extracted from the `http` example) were not.

This commit updates the HTTP guide examples to also use
`TestBed.inject()`.

[1]: https://v9.angular.io/guide/deprecations#testing

Fixes #35609

PR Close #35777
This commit is contained in:
George Kalpakas 2020-02-29 17:47:18 +02:00 committed by atscott
parent c195d22f68
commit bf42807aa6
2 changed files with 6 additions and 6 deletions

View File

@ -28,9 +28,9 @@ describe('HeroesService', () => {
// Inject the http, test controller, and service-under-test
// as they will be referenced by each test.
httpClient = TestBed.get(HttpClient);
httpTestingController = TestBed.get(HttpTestingController);
heroService = TestBed.get(HeroesService);
httpClient = TestBed.inject(HttpClient);
httpTestingController = TestBed.inject(HttpTestingController);
heroService = TestBed.inject(HeroesService);
});
afterEach(() => {
@ -44,7 +44,7 @@ describe('HeroesService', () => {
let expectedHeroes: Hero[];
beforeEach(() => {
heroService = TestBed.get(HeroesService);
heroService = TestBed.inject(HeroesService);
expectedHeroes = [
{ id: 1, name: 'A' },
{ id: 2, name: 'B' },

View File

@ -27,8 +27,8 @@ describe('HttpClient testing', () => {
});
// Inject the http service and test controller for each test
httpClient = TestBed.get(HttpClient);
httpTestingController = TestBed.get(HttpTestingController);
httpClient = TestBed.inject(HttpClient);
httpTestingController = TestBed.inject(HttpTestingController);
});
// #enddocregion setup
// #docregion afterEach