Skip to content

Instantly share code, notes, and snippets.

@joeeames
Created November 17, 2020 22:54
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save joeeames/15da7c72990421eb5303fcc035c13c49 to your computer and use it in GitHub Desktop.
Save joeeames/15da7c72990421eb5303fcc035c13c49 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