File tree Expand file tree Collapse file tree 1 file changed +41
-0
lines changed
angular-reactive-validation/src/form Expand file tree Collapse file tree 1 file changed +41
-0
lines changed Original file line number Diff line number Diff line change 1+ import { Component } from '@angular/core' ;
2+ import { FormGroup , ReactiveFormsModule } from '@angular/forms' ;
3+ import { TestBed } from '@angular/core/testing' ;
4+ import { FormDirective } from './form.directive' ;
5+ import { By } from '@angular/platform-browser' ;
6+
7+ describe ( 'FormDirective' , ( ) => {
8+ it ( `submitted observable emits when the form is submitted` , ( ) => {
9+ TestBed . configureTestingModule ( {
10+ imports : [ ReactiveFormsModule ] ,
11+ declarations : [ FormDirective , TestHostComponent ]
12+ } ) ;
13+
14+ const fixture = TestBed . createComponent ( TestHostComponent ) ;
15+ fixture . detectChanges ( ) ;
16+
17+ const formDirective = fixture . debugElement
18+ . query ( By . directive ( FormDirective ) )
19+ . injector . get ( FormDirective ) ;
20+
21+ let called = false ;
22+ formDirective . submitted . subscribe ( ( ) => {
23+ called = true ;
24+ } ) ;
25+
26+ const button = fixture . debugElement . nativeElement . querySelector ( 'button' ) ;
27+ button . click ( ) ;
28+
29+ expect ( called ) . toEqual ( true ) ;
30+ } ) ;
31+
32+ @Component ( {
33+ template : `
34+ <form [formGroup]="form">
35+ <button type="submit"></button>
36+ </form>`
37+ } )
38+ class TestHostComponent {
39+ form = new FormGroup ( { } ) ;
40+ }
41+ } ) ;
You can’t perform that action at this time.
0 commit comments