Created
January 22, 2019 16:13
-
-
Save latish/bc9ecf7451c42ab4e6c9ef26cf571eda 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 { HeroDetailContainerComponent } from "./hero-detail.container.component"; | |
import { Hero } from "../hero"; | |
import { of } from "rxjs"; | |
describe('Hero Detail Component', ()=>{ | |
let component, routeMock, paramMock, heroServiceMock, locationMock; | |
beforeEach(()=>{ | |
paramMock = jasmine.createSpyObj('paramMap', ['get']); | |
routeMock = {snapshot:{paramMap:paramMock}}; | |
heroServiceMock = jasmine.createSpyObj('heroService', ['getHero', 'updateHero']); | |
locationMock = jasmine.createSpyObj('location', ['back']); | |
}) | |
it('should fetch hero details on creation', ()=>{ | |
const HERO_ID = 42; | |
paramMock.get.and.returnValue(HERO_ID); | |
component = new HeroDetailContainerComponent(routeMock, heroServiceMock, locationMock); | |
expect(heroServiceMock.getHero).toHaveBeenCalledWith(HERO_ID); | |
}) | |
it('should save hero details', ()=>{ | |
const hero:Hero = { | |
id: 42, | |
name: 'Arthur Dent' | |
}; | |
heroServiceMock.updateHero.and.returnValue(of({})); | |
component = new HeroDetailContainerComponent(routeMock, heroServiceMock, locationMock); | |
component.save(hero); | |
expect(heroServiceMock.updateHero).toHaveBeenCalledWith(hero); | |
}) | |
it('should navigate back on saving hero details', ()=>{ | |
const hero:Hero = { | |
id: 42, | |
name: 'Arthur Dent' | |
}; | |
heroServiceMock.updateHero.and.returnValue(of({})); | |
component = new HeroDetailContainerComponent(routeMock, heroServiceMock, locationMock); | |
component.save(hero); | |
expect(locationMock.back).toHaveBeenCalled(); | |
}) | |
}) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment