Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix(#316): better support for typeIn and ngModel
- Loading branch information
Showing
3 changed files
with
82 additions
and
3 deletions.
There are no files selected for viewing
17 changes: 15 additions & 2 deletions
17
libs/ng-mocks/src/lib/mock-helper/cva/mock-helper.change.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,53 @@ | ||
import { Component, NgModule } from '@angular/core'; | ||
import { | ||
FormControl, | ||
FormsModule, | ||
ReactiveFormsModule, | ||
} from '@angular/forms'; | ||
import { MatInputModule } from '@angular/material/input'; | ||
import { MockBuilder, MockRender, ngMocks } from 'ng-mocks'; | ||
|
||
@Component({ | ||
selector: 'target', | ||
template: ` | ||
<input | ||
type="text" | ||
matInput | ||
[formControl]="control" | ||
name="form-control" | ||
/> | ||
<input type="text" matInput [(ngModel)]="value" name="ng-model" /> | ||
`, | ||
}) | ||
class TargetComponent { | ||
public readonly control = new FormControl(); | ||
public value; | ||
} | ||
|
||
@NgModule({ | ||
declarations: [TargetComponent], | ||
imports: [FormsModule, ReactiveFormsModule, MatInputModule], | ||
}) | ||
class TargetModule {} | ||
|
||
describe('mat-input', () => { | ||
describe('real', () => { | ||
beforeEach(() => MockBuilder(TargetComponent).keep(TargetModule)); | ||
|
||
it('changes values', () => { | ||
const component = MockRender(TargetComponent).point | ||
.componentInstance; | ||
const input1 = ngMocks.find(['name', 'form-control']); | ||
const input2 = ngMocks.find(['name', 'ng-model']); | ||
|
||
ngMocks.change(input1, 'input1'); | ||
expect(component.control.value).toEqual('input1'); | ||
|
||
ngMocks.change(input2, 'input2'); | ||
expect(component.value).toEqual('input2'); | ||
|
||
ngMocks.output(input2, 'ngModelChange').emit('input3'); | ||
expect(component.value).toEqual('input3'); | ||
}); | ||
}); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters