Created
November 17, 2020 22:54
-
-
Save joeeames/15da7c72990421eb5303fcc035c13c49 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