feat(button): add first real unit test

This commit is contained in:
Jeremy Elbourn
2016-01-08 10:10:18 -08:00
parent 3ed5302bba
commit 9d2533c089
+18 -8
View File
@@ -11,7 +11,10 @@ import {
beforeEach,
} from 'angular2/testing';
import {provide, Component} from 'angular2/core';
import {DebugElement} from "angular2/core";
import {MdButton} from './button';
import {AsyncTestFn} from "angular2/testing";
describe('MdButton', () => {
@@ -19,18 +22,25 @@ describe('MdButton', () => {
beforeEach(inject([TestComponentBuilder], (tcb: TestComponentBuilder) => { builder = tcb; }));
it('should ...', () => {
return builder.createAsync(MdButton).then((fixture) => {
fixture.detectChanges();
describe('button[md-button]', () => {
it('should handle a click on the button', (done: () => void) => {
return builder.createAsync(TestApp).then((fixture) => {
let testComponent = fixture.debugElement.componentInstance;
let buttonDebugElement = getChildDebugElement(fixture.debugElement, 'button');
buttonDebugElement.nativeElement.click();
expect(testComponent.clickCount).toBe(1);
done();
});
});
});
});
/** Gets a child DebugElement by tag name. */
function getChildDebugElement(parent: DebugElement, tagName: string): DebugElement {
return parent.query(debugEl => debugEl.nativeElement.tagName.toLowerCase() == tagName);
}
/** Test component that contains an MdButton. */
@Component({