mirror of
https://github.com/angular/angular.git
synced 2026-09-14 13:54:52 +08:00
feat(button): add first real unit test
This commit is contained in:
@@ -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({
|
||||
|
||||
Reference in New Issue
Block a user