-
-
Save ElenaG518/959a18e1c4fd726862e30bb2d148ab38 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import { DebugElement } from "@angular/core"; | |
import { ComponentFixture, TestBed } from "@angular/core/testing" | |
import { By } from "@angular/platform-browser"; | |
import { HeroComponent } from "./hero.component" | |
describe('HeroComponent (integration tests)', () => { | |
let fixture: ComponentFixture<HeroComponent>; | |
beforeEach(() => { | |
TestBed.configureTestingModule({ | |
declarations: [HeroComponent] | |
}) | |
fixture = TestBed.createComponent(HeroComponent); | |
}) | |
it('should have the correct hero', () => { | |
fixture.componentInstance.hero = { | |
id: 1, name: 'Star Lord', strength: 5 | |
} | |
expect(fixture.componentInstance.hero.name).toEqual('Star Lord'); | |
}); | |
it('should display the name', () => { | |
fixture.componentInstance.hero = { | |
id: 1, name: 'Star Lord', strength: 5 | |
} | |
fixture.detectChanges(); | |
let text = fixture.nativeElement.querySelector('a').textContent; | |
expect(text).toContain('Star Lord'); | |
let text2 = fixture.debugElement.query(By.css('a')).nativeElement.textContent; | |
expect(text2).toContain('Star Lord'); | |
}) | |
}) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment