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

View File

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