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:
parent
c195d22f68
commit
bf42807aa6
|
@ -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' },
|
||||
|
|
|
@ -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
|
||||
|
|
Loading…
Reference in New Issue