import { Component } from '@angular/core' ; import { Context , dispatchInputEvent , setupTemplateDrivenForms } from './spec-utils' ; @ Component ( { template : `
  <form>
    <input type="date" [(ngModel)]="testDate" name="someName">
  </form>` } ) export class TestFormComponent { testDate : Date | string = new Date ( '2020-01-01' ) ; } describe ( 'DefaultValueAccessor (template-driven forms)' , ( ) => { let c = { } ; setupTemplateDrivenForms ( c , TestFormComponent ) ; it ( 'should NOT reflect changes from the model to the input after init (when using dates)' , ( ) => { expect ( c . fixture . componentInstance . testDate ) . toEqual ( new Date ( '2020-01-01' ) ) ; expect ( c . inputElement . value ) . toBe ( '' ) ; } ) ; it ( 'should reflect changes from the input to the model, BUT returns simple strings' , ( ) => { dispatchInputEvent ( c . inputElement , '2020-12-31' ) ; expect ( c . fixture . componentInstance . testDate ) . toEqual ( '2020-12-31' ) ; } ) ; it ( 'IMPORTANT: should populate EMPTY STRING for invalid dates' , ( ) => { dispatchInputEvent ( c . inputElement , "NOT A DATE" ) ; expect ( c . fixture . componentInstance . testDate ) . toBe ( '' ) ; expect ( c . inputElement . value ) . toBe ( '' ) ; } ) ; } ) ;