-
Notifications
You must be signed in to change notification settings - Fork 93
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: add detectChanges function (#45)
- Loading branch information
1 parent
3e7f485
commit 8a6fe17
Showing
3 changed files
with
58 additions
and
7 deletions.
There are no files selected for viewing
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
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,43 @@ | ||
import { Component, OnInit } from '@angular/core'; | ||
import { fakeAsync, tick } from '@angular/core/testing'; | ||
import { FormControl, ReactiveFormsModule } from '@angular/forms'; | ||
import { delay } from 'rxjs/operators'; | ||
import { render } from '../src/public_api'; | ||
|
||
@Component({ | ||
selector: 'fixture', | ||
template: ` | ||
<input type="text" data-testid="input" [formControl]="inputControl" /> | ||
<button data-testid="button">{{ caption }}</button> | ||
`, | ||
}) | ||
class FixtureComponent implements OnInit { | ||
inputControl = new FormControl(); | ||
caption = 'Button'; | ||
|
||
ngOnInit() { | ||
this.inputControl.valueChanges.pipe(delay(400)).subscribe(() => (this.caption = 'Button updated after 400ms')); | ||
} | ||
} | ||
|
||
describe('detectChanges', () => { | ||
test('does not recognize change if execution is delayed', async () => { | ||
const { getByTestId, type } = await render(FixtureComponent, { imports: [ReactiveFormsModule] }); | ||
|
||
type(getByTestId('input'), 'What a great day!'); | ||
expect(getByTestId('button').innerHTML).toBe('Button'); | ||
}); | ||
|
||
test('exposes detectChanges triggering a change detection cycle', fakeAsync(async () => { | ||
const { getByTestId, type, detectChanges } = await render(FixtureComponent, { | ||
imports: [ReactiveFormsModule], | ||
}); | ||
|
||
type(getByTestId('input'), 'What a great day!'); | ||
|
||
tick(500); | ||
detectChanges(); | ||
|
||
expect(getByTestId('button').innerHTML).toBe('Button updated after 400ms'); | ||
})); | ||
}); |