Skip to content

Instantly share code, notes, and snippets.

@hartraft
Last active November 8, 2017 09:38
Show Gist options
  • Save hartraft/adcca2ab7e5b3938fb833b942914df66 to your computer and use it in GitHub Desktop.
Save hartraft/adcca2ab7e5b3938fb833b942914df66 to your computer and use it in GitHub Desktop.
TS Spec template to cover standard testing cases. Uncomment sections that are needed. Can be inserted into WebStorm / IntelliJ as a file template
import {DebugElement} from '@angular/core';
import {async, ComponentFixture, ComponentFixtureAutoDetect, TestBed} from '@angular/core/testing';
import {By} from '@angular/platform-browser';
// import {RouterTestingModule} from '@angular/router/testing';
describe('ComponentUnderTest ', () => {
let comp: ComponentUnderTest;
let fixture: ComponentFixture<ComponentUnderTest>;
let de: DebugElement;
let el: HTMLElement;
// let responseStub: any = {};
// let serviceStub = {
// stubMethod( used: boolean ): any {
// return Promise.resolve( null );
// }
// };
// async
beforeEach(async(() => {
TestBed.configureTestingModule({
declarations: [ComponentUnderTest],
// imports: [RouterTestingModule], // only needed if router is involved
providers: [
{provide: ComponentFixtureAutoDetect, useValue: true}
// , { provide: DependencyService, useValue: serviceStub }
]
}).compileComponents();
// spyOn(serviceStub, 'stubMethod').and.returnValue(Promise.resolve(responseStub));
}));
beforeEach(async(() => {
fixture = TestBed.createComponent(ComponentUnderTest);
comp = fixture.componentInstance;
de = fixture.debugElement.query(By.css('h1'));
el = de.nativeElement;
}));
it('return a test', () => {
fixture.detectChanges();
expect(false).toBe(true);
});
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment