-
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.
- Loading branch information
1 parent
5e17e95
commit d7b4f48
Showing
2 changed files
with
50 additions
and
0 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
import { TestbedHarnessEnvironment } from '@angular/cdk/testing/testbed'; | ||
import { MatButtonHarness } from '@angular/material/button/testing'; | ||
import { MatSnackBarHarness } from '@angular/material/snack-bar/testing'; | ||
import { render, screen } from '@testing-library/angular'; | ||
import user from '@testing-library/user-event'; | ||
|
||
import { SnackBarComponent } from './20-test-harness'; | ||
|
||
test('can be used with TestHarness', async () => { | ||
const view = await render(SnackBarComponent); | ||
const loader = TestbedHarnessEnvironment.documentRootLoader(view.fixture); | ||
|
||
const buttonHarness = await loader.getHarness(MatButtonHarness); | ||
const button = await buttonHarness.host(); | ||
button.click(); | ||
|
||
const snackbarHarness = await loader.getHarness(MatSnackBarHarness); | ||
expect(await snackbarHarness.getMessage()).toMatch(/Pizza Party!!!/i); | ||
}); | ||
|
||
test('can be used in combination with TestHarness', async () => { | ||
const view = await render(SnackBarComponent); | ||
const loader = TestbedHarnessEnvironment.documentRootLoader(view.fixture); | ||
|
||
user.click(screen.getByRole('button')); | ||
|
||
const snackbarHarness = await loader.getHarness(MatSnackBarHarness); | ||
expect(await snackbarHarness.getMessage()).toMatch(/Pizza Party!!!/i); | ||
|
||
expect(screen.getByText(/Pizza Party!!!/i)).toBeInTheDocument(); | ||
}); |
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,19 @@ | ||
import { Component } from '@angular/core'; | ||
import { MatButtonModule } from '@angular/material/button'; | ||
import { MatSnackBar, MatSnackBarModule } from '@angular/material/snack-bar'; | ||
|
||
@Component({ | ||
selector: 'app-harness', | ||
standalone: true, | ||
imports: [MatButtonModule, MatSnackBarModule], | ||
template: ` | ||
<button mat-stroked-button (click)="openSnackBar()" aria-label="Show an example snack-bar">Pizza party</button> | ||
`, | ||
}) | ||
export class SnackBarComponent { | ||
constructor(private snackBar: MatSnackBar) {} | ||
|
||
openSnackBar() { | ||
return this.snackBar.open('Pizza Party!!!'); | ||
} | ||
} |