-
Notifications
You must be signed in to change notification settings - Fork 92
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: add ability to turn off auto detect changes (#329)
- Loading branch information
1 parent
ce3a612
commit 50aa0ac
Showing
3 changed files
with
60 additions
and
22 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 |
---|---|---|
@@ -1,17 +1,48 @@ | ||
import { Component } from '@angular/core'; | ||
import { render, fireEvent, screen } from '../src/public_api'; | ||
import { FormsModule } from '@angular/forms'; | ||
|
||
@Component({ | ||
selector: 'atl-fixture', | ||
template: ` <input type="text" data-testid="input" /> `, | ||
}) | ||
class FixtureComponent {} | ||
describe('fireEvent', () => { | ||
@Component({ | ||
selector: 'atl-fixture', | ||
template: ` <input type="text" data-testid="input" [(ngModel)]="name" name="name" /> | ||
<div>Hello {{ name }}</div>`, | ||
}) | ||
class FixtureComponent { | ||
name = ''; | ||
} | ||
|
||
test('does not call detect changes when fixture is destroyed', async () => { | ||
const { fixture } = await render(FixtureComponent); | ||
it('automatically detect changes when event is fired', async () => { | ||
await render(FixtureComponent, { | ||
imports: [FormsModule], | ||
}); | ||
|
||
fixture.destroy(); | ||
fireEvent.input(screen.getByTestId('input'), { target: { value: 'Tim' } }); | ||
|
||
// should otherwise throw | ||
fireEvent.input(screen.getByTestId('input'), { target: { value: 'Bonjour' } }); | ||
expect(screen.getByText('Hello Tim')).toBeInTheDocument(); | ||
}); | ||
|
||
it('can disable automatic detect changes when event is fired', async () => { | ||
const { detectChanges } = await render(FixtureComponent, { | ||
imports: [FormsModule], | ||
autoDetectChanges: false, | ||
}); | ||
|
||
fireEvent.input(screen.getByTestId('input'), { target: { value: 'Tim' } }); | ||
|
||
expect(screen.queryByText('Hello Tim')).not.toBeInTheDocument(); | ||
|
||
detectChanges(); | ||
|
||
expect(screen.getByText('Hello Tim')).toBeInTheDocument(); | ||
}); | ||
|
||
it('does not call detect changes when fixture is destroyed', async () => { | ||
const { fixture } = await render(FixtureComponent); | ||
|
||
fixture.destroy(); | ||
|
||
// should otherwise throw | ||
fireEvent.input(screen.getByTestId('input'), { target: { value: 'Bonjour' } }); | ||
}); | ||
}); |