feat(demo): unit test the ngModel binding

This commit is contained in:
Ken Sodemann
2017-11-15 20:41:35 -06:00
parent 9599981723
commit 039759815f
4 changed files with 69 additions and 5 deletions

View File

@ -29,4 +29,27 @@ describe('InputsTestPageComponent', () => {
it('should create', () => {
expect(component).toBeTruthy();
});
describe('testInputOne binding', () => {
let input;
beforeEach(
fakeAsync(() => {
component.ngOnInit();
fixture.detectChanges();
tick();
input = fixture.debugElement.query(By.css('#stdTextInput')).nativeElement;
// This is what I ultimtely want to test...
//
// const ionInput = fixture.debugElement.query(By.css('#ionTextInput'));
// input = ionInput.query(By.css('input')).nativeElement;
})
);
it('should reflect changes to the input', () => {
expect(input).toBeTruthy();
input.value = 'Frank';
input.dispatchEvent(new Event('input'));
expect(component.textValue).toEqual('Frank');
});
});
});

View File

@ -1,7 +1,9 @@
import { CUSTOM_ELEMENTS_SCHEMA } from '@angular/core';
import { async, ComponentFixture, TestBed } from '@angular/core/testing';
import { FormsModule } from '@angular/forms';
import { GroupInputsPageComponent } from './group-inputs-page.component';
import { SharedModule } from '../shared/shared.module';
describe('GroupInputsPageComponent', () => {
let component: GroupInputsPageComponent;
@ -10,6 +12,7 @@ describe('GroupInputsPageComponent', () => {
beforeEach(
async(() => {
TestBed.configureTestingModule({
imports: [FormsModule, SharedModule],
declarations: [GroupInputsPageComponent],
schemas: [CUSTOM_ELEMENTS_SCHEMA]
}).compileComponents();