
committed by
Kara Erickson

parent
ebd01e8e79
commit
5649acd03f
@ -0,0 +1,76 @@
|
||||
// #docregion
|
||||
import { async, ComponentFixture, TestBed, tick, fakeAsync } from '@angular/core/testing';
|
||||
import { FormsModule } from '@angular/forms';
|
||||
|
||||
import { createNewEvent } from '../../shared/utils';
|
||||
import { TemplateNameComponent } from './name.component';
|
||||
|
||||
// #docregion tests
|
||||
describe('Template Name Component', () => {
|
||||
// #enddocregion tests
|
||||
let component: TemplateNameComponent;
|
||||
let fixture: ComponentFixture<TemplateNameComponent>;
|
||||
|
||||
beforeEach(async(() => {
|
||||
TestBed.configureTestingModule({
|
||||
imports: [FormsModule],
|
||||
declarations: [TemplateNameComponent]
|
||||
})
|
||||
.compileComponents();
|
||||
}));
|
||||
|
||||
beforeEach(() => {
|
||||
fixture = TestBed.createComponent(TemplateNameComponent);
|
||||
component = fixture.componentInstance;
|
||||
fixture.detectChanges();
|
||||
});
|
||||
|
||||
it('should create', () => {
|
||||
expect(component).toBeTruthy();
|
||||
});
|
||||
|
||||
// #docregion tests
|
||||
it('should update the value in the control', fakeAsync(() => {
|
||||
// update the component instance variable
|
||||
component.name = 'Nancy';
|
||||
|
||||
// run change detection
|
||||
fixture.detectChanges();
|
||||
|
||||
// advance after change detection cycle
|
||||
tick();
|
||||
|
||||
// query the element
|
||||
const input = fixture.nativeElement.querySelector('input');
|
||||
|
||||
expect(input.value).toBe('Nancy');
|
||||
}));
|
||||
|
||||
it('should update the value of the input field', fakeAsync(() => {
|
||||
// update component instance variable
|
||||
component.name = 'Nancy';
|
||||
|
||||
// run change detection
|
||||
fixture.detectChanges();
|
||||
|
||||
// advance after change detection cycle
|
||||
tick();
|
||||
|
||||
// query the element
|
||||
const input = fixture.nativeElement.querySelector('input');
|
||||
expect(input.value).toEqual('Nancy');
|
||||
|
||||
// update the form field value
|
||||
input.value = 'Smith';
|
||||
|
||||
// Use utility function to create custom event, then dispatch on the input
|
||||
const event = createNewEvent('input');
|
||||
input.dispatchEvent(event);
|
||||
|
||||
// advance after change detection cycle
|
||||
tick();
|
||||
|
||||
expect(component.name).toEqual('Smith');
|
||||
}));
|
||||
});
|
||||
// #enddocregion
|
@ -0,0 +1,16 @@
|
||||
// #docplaster
|
||||
// #docregion
|
||||
import { Component } from '@angular/core';
|
||||
|
||||
@Component({
|
||||
// #enddocregion
|
||||
selector: 'app-template-name',
|
||||
// #docregion
|
||||
template: `
|
||||
Name: <input type="text" [(ngModel)]="name">
|
||||
`
|
||||
})
|
||||
export class TemplateNameComponent {
|
||||
name = '';
|
||||
}
|
||||
// #enddocregion
|
@ -0,0 +1,13 @@
|
||||
import { TemplateModule } from './template.module';
|
||||
|
||||
describe('TemplateModule', () => {
|
||||
let templateModule: TemplateModule;
|
||||
|
||||
beforeEach(() => {
|
||||
templateModule = new TemplateModule();
|
||||
});
|
||||
|
||||
it('should create an instance', () => {
|
||||
expect(templateModule).toBeTruthy();
|
||||
});
|
||||
});
|
@ -0,0 +1,14 @@
|
||||
import { NgModule } from '@angular/core';
|
||||
import { CommonModule } from '@angular/common';
|
||||
import { TemplateNameComponent } from './name/name.component';
|
||||
import { FormsModule } from '@angular/forms';
|
||||
|
||||
@NgModule({
|
||||
imports: [
|
||||
CommonModule,
|
||||
FormsModule
|
||||
],
|
||||
declarations: [TemplateNameComponent],
|
||||
exports: [TemplateNameComponent]
|
||||
})
|
||||
export class TemplateModule { }
|
Reference in New Issue
Block a user