Created
August 4, 2017 20:58
-
-
Save karan-kang/7e36e846facc983c45229a1e18d7ae9c 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 { async, ComponentFixture, fakeAsync, TestBed, tick } from '@angular/core/testing'; | |
import { By } from '@angular/platform-browser'; | |
import { | |
AppPanelService, | |
ExpandPanelComponent | |
} from './index'; | |
describe('shared.ExpandPanelComponent', () => { | |
let fixture: ComponentFixture<ExpandPanelComponent>; | |
let component: ExpandPanelComponent; | |
let service: any; | |
let expanded = false; | |
beforeEach(async(() => { | |
// Mocked service | |
service = jasmine.createSpyObj('AppPanelServiceMock', [ | |
'expandPanel', 'getPanelElement' | |
]); | |
service.expandPanel.and.callFake(() => { | |
return expanded; | |
}); | |
service.getPanelElement.and.callFake(() => { | |
return { | |
panel: 'element' | |
}; | |
}); | |
TestBed.configureTestingModule({ | |
declarations: [ | |
ExpandPanelComponent | |
], | |
providers: [ | |
{ | |
provide: AppPanelService, | |
useValue: service | |
} | |
] | |
}); | |
TestBed.compileComponents().then(() => { | |
fixture = TestBed.createComponent(ExpandPanelComponent); | |
component = fixture.componentInstance; | |
}); | |
})); | |
it('should get instance', () => { | |
expect(component).toBeDefined(); | |
}); | |
it('should throw exception if no panel element', fakeAsync(() => { | |
service.getPanelElement.and.callFake(() => { | |
return null; | |
}); | |
expect(component.ngOnInit()).toThrow(); | |
})); | |
it('should call expand method', fakeAsync(() => { | |
expanded = true; | |
const anchor = fixture.debugElement.query(By.css('a')); | |
anchor.triggerEventHandler('click', null); | |
tick(); | |
fixture.detectChanges(); | |
expect(service.expandPanel).toHaveBeenCalled(); | |
expect(component.expanded).toBe(expanded); | |
})); | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment