Skip to content

Instantly share code, notes, and snippets.

@ElenaG518
Forked from joeeames/test1
Created August 24, 2021 23:38
Show Gist options
  • Save ElenaG518/959a18e1c4fd726862e30bb2d148ab38 to your computer and use it in GitHub Desktop.
Save ElenaG518/959a18e1c4fd726862e30bb2d148ab38 to your computer and use it in GitHub Desktop.
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