New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
docs: fix unit tests in toh-pt6 #24491
Conversation
@@ -1,16 +1,36 @@ | |||
import { async, ComponentFixture, TestBed } from '@angular/core/testing'; | |||
|
|||
import { DashboardComponent } from './dashboard.component'; | |||
import { HeroSearchComponent } from '../hero-search/hero-search.component'; | |||
|
|||
import { RouterModule } from '@angular/router'; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Use RouterTestingModule
from @angular/router/testing
instead.
HeroSearchComponent | ||
], | ||
imports: [ | ||
RouterModule.forRoot([]) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This should be RouterTestingModule.withRoutes([])
. Then you don't need to provide the APP_BASE_HREF
in the tests
declarations: [ HeroSearchComponent ] | ||
declarations: [ HeroSearchComponent ], | ||
imports: [RouterModule.forRoot([]), HttpClientModule], | ||
providers: [{ provide: APP_BASE_HREF, useValue: '/' }] |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This should use HttpClientTestingModule
and RouterTestingModule
|
||
describe('HeroesComponent', () => { | ||
let component: HeroesComponent; | ||
let fixture: ComponentFixture<HeroesComponent>; | ||
|
||
beforeEach(async(() => { | ||
TestBed.configureTestingModule({ | ||
declarations: [ HeroesComponent ] | ||
declarations: [ HeroesComponent ], | ||
imports: [RouterModule.forRoot([]), HttpClientModule], |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Same as above. Use RouterTestingModule
and remove APP_BASE_HREF
|
||
describe('DashboardComponent', () => { | ||
let component: DashboardComponent; | ||
let fixture: ComponentFixture<DashboardComponent>; | ||
const heroService = jasmine.createSpyObj('HeroService', ['getHeroes']); | ||
const getHeroesSpy = heroService.getHeroes.and.returnValue( of(HEROES) ); | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The spies should be set in the beforeEach
, so they are reset for each test
Changes LGTM: Will you squash down to a single commit and change the commit message to Thanks |
Resolves #20373
This issue has been automatically locked due to inactivity. Read more about our automatic conversation locking policy. This action has been performed automatically by a bot. |
Added some tests to dashboard.component.spec
Resolves #20373
PR Checklist
Please check if your PR fulfills the following requirements:
PR Type
What kind of change does this PR introduce?
What is the current behavior?
executing ng test resulted in an error
Issue Number: 20373
What is the new behavior?
Tests are running
Does this PR introduce a breaking change?
Other information