Last active
November 17, 2020 23:23
-
-
Save joeeames/f516b32941e645f23bae8c9f6cc7038e 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 { of } from "rxjs"; | |
import { HeroService } from "../hero.service"; | |
import { HeroesComponent } from "./heroes.component" | |
describe('HeroComponent (integration tests)', () => { | |
let fixture: ComponentFixture<HeroesComponent>; | |
let mockHeroService; | |
let HEROES = [ | |
{id: 1, name: 'Superman', strength: 100}, | |
{id: 2, name: 'Batman', strength: 9}, | |
{id: 3, name: 'Star Lord', strength: 5} | |
] | |
beforeEach(() => { | |
mockHeroService = jasmine.createSpyObj(['getHeroes', 'deleteHero', 'addHero']); | |
TestBed.configureTestingModule({ | |
declarations: [HeroesComponent], | |
providers: [ | |
{provide: HeroService, useValue: mockHeroService } | |
], | |
}) | |
fixture = TestBed.createComponent(HeroesComponent); | |
mockHeroService.getHeroes.and.returnValue(of(HEROES)); | |
}) | |
it('should do something', () => { | |
fixture.detectChanges(); | |
expect(fixture.componentInstance.heroes.length).toBe(3); | |
}) | |
it('should have 3 li tags after initialization') | |
}) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment