Skip to content

Commit d0684e3

Browse files
test: resolve skipped tests (#560)
1 parent 57ced23 commit d0684e3

File tree

6 files changed

+100
-10
lines changed

6 files changed

+100
-10
lines changed

apps/example-app-jest/src/app/examples/02-input-output.spec.ts

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -66,6 +66,34 @@ test('is possible to set input and listen for output (deprecated)', async () =>
6666
expect(sendValue).toHaveBeenCalledWith(50);
6767
});
6868

69+
test('is possible to set input and listen for output with the template syntax', async () => {
70+
const user = userEvent.setup();
71+
const sendSpy = jest.fn();
72+
73+
await render('<atl-fixture [value]="47" (sendValue)="sendValue($event)" />', {
74+
imports: [InputOutputComponent],
75+
componentProperties: {
76+
sendValue: sendSpy,
77+
},
78+
providers: [provideZoneChangeDetection()],
79+
});
80+
81+
const incrementControl = screen.getByRole('button', { name: /increment/i });
82+
const sendControl = screen.getByRole('button', { name: /send/i });
83+
const valueControl = screen.getByTestId('value');
84+
85+
expect(valueControl).toHaveTextContent('47');
86+
87+
await user.click(incrementControl);
88+
await user.click(incrementControl);
89+
await user.click(incrementControl);
90+
expect(valueControl).toHaveTextContent('50');
91+
92+
await user.click(sendControl);
93+
expect(sendSpy).toHaveBeenCalledTimes(1);
94+
expect(sendSpy).toHaveBeenCalledWith(50);
95+
});
96+
6997
test('is possible to set input and listen for output with the template syntax (deprecated)', async () => {
7098
const user = userEvent.setup();
7199
const sendSpy = jest.fn();
Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
import { provideZoneChangeDetection } from '@angular/core';
2+
import { TestbedHarnessEnvironment } from '@angular/cdk/testing/testbed';
3+
import { MatButtonHarness } from '@angular/material/button/testing';
4+
import { MatSnackBarHarness } from '@angular/material/snack-bar/testing';
5+
import { render, screen } from '@testing-library/angular';
6+
import userEvent from '@testing-library/user-event';
7+
8+
import { HarnessComponent } from './20-test-harness';
9+
10+
test.skip('can be used with TestHarness', async () => {
11+
const view = await render(`<atl-harness />`, {
12+
imports: [HarnessComponent],
13+
providers: [provideZoneChangeDetection()],
14+
});
15+
const loader = TestbedHarnessEnvironment.documentRootLoader(view.fixture);
16+
17+
const buttonHarness = await loader.getHarness(MatButtonHarness);
18+
const button = await buttonHarness.host();
19+
button.click();
20+
21+
const snackbarHarness = await loader.getHarness(MatSnackBarHarness);
22+
expect(await snackbarHarness.getMessage()).toMatch(/Pizza Party!!!/i);
23+
});
24+
25+
test.skip('can be used in combination with TestHarness', async () => {
26+
const user = userEvent.setup();
27+
28+
const view = await render(HarnessComponent, {
29+
providers: [provideZoneChangeDetection()],
30+
});
31+
const loader = TestbedHarnessEnvironment.documentRootLoader(view.fixture);
32+
33+
await user.click(screen.getByRole('button'));
34+
35+
const snackbarHarness = await loader.getHarness(MatSnackBarHarness);
36+
expect(await snackbarHarness.getMessage()).toMatch(/Pizza Party!!!/i);
37+
38+
expect(screen.getByText(/Pizza Party!!!/i)).toBeInTheDocument();
39+
});
Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
import { Component, inject } from '@angular/core';
2+
import { MatButtonModule } from '@angular/material/button';
3+
import { MatSnackBar, MatSnackBarModule } from '@angular/material/snack-bar';
4+
5+
@Component({
6+
selector: 'atl-harness',
7+
standalone: true,
8+
imports: [MatButtonModule, MatSnackBarModule],
9+
template: `
10+
<button mat-stroked-button (click)="openSnackBar()" aria-label="Show an example snack-bar">Pizza party</button>
11+
`,
12+
})
13+
export class HarnessComponent {
14+
private snackBar = inject(MatSnackBar);
15+
16+
openSnackBar() {
17+
return this.snackBar.open('Pizza Party!!!');
18+
}
19+
}

apps/example-app/src/app/examples/02-input-output.spec.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -33,13 +33,13 @@ test('is possible to set input and listen for output', async () => {
3333
expect(sendValue).toHaveBeenCalledWith(50);
3434
});
3535

36-
test.skip('is possible to set input and listen for output with the template syntax', async () => {
36+
test('is possible to set input and listen for output with the template syntax', async () => {
3737
const user = userEvent.setup();
3838
const sendSpy = vi.fn();
3939

4040
await render('<atl-fixture [value]="47" (sendValue)="sendValue($event)" />', {
4141
imports: [InputOutputComponent],
42-
on: {
42+
componentProperties: {
4343
sendValue: sendSpy,
4444
},
4545
});

apps/example-app/src/app/examples/20-test-harness.spec.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ import userEvent from '@testing-library/user-event';
77

88
import { HarnessComponent } from './20-test-harness';
99

10-
test.skip('can be used with TestHarness', async () => {
10+
test('can be used with TestHarness', async () => {
1111
const view = await render(`<atl-harness />`, {
1212
imports: [HarnessComponent],
1313
});
@@ -21,7 +21,7 @@ test.skip('can be used with TestHarness', async () => {
2121
expect(await snackbarHarness.getMessage()).toMatch(/Pizza Party!!!/i);
2222
});
2323

24-
test.skip('can be used in combination with TestHarness', async () => {
24+
test('can be used in combination with TestHarness', async () => {
2525
const user = userEvent.setup();
2626

2727
const view = await render(HarnessComponent);

projects/testing-library/src/tests/integration.spec.ts

Lines changed: 10 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ import { TestBed } from '@angular/core/testing';
33
import { vi, test, expect, afterEach } from 'vitest';
44
import { of, BehaviorSubject } from 'rxjs';
55
import { debounceTime, switchMap, map, startWith } from 'rxjs/operators';
6-
import { render, screen, waitFor, waitForElementToBeRemoved, within } from '../lib/testing-library';
6+
import { render, screen, waitForElementToBeRemoved, within } from '../lib/testing-library';
77
import userEvent from '@testing-library/user-event';
88
import { AsyncPipe, NgForOf } from '@angular/common';
99

@@ -98,7 +98,9 @@ afterEach(() => {
9898

9999
async function setup() {
100100
vi.useFakeTimers();
101-
const user = userEvent.setup();
101+
const user = userEvent.setup({
102+
advanceTimers: vi.advanceTimersByTime,
103+
});
102104

103105
await render(EntitiesComponent, {
104106
providers: [
@@ -139,7 +141,7 @@ test('renders the entities', async () => {
139141
expect(await screen.findByRole('cell', { name: /Entity 3/i })).toBeInTheDocument();
140142
});
141143

142-
test.skip('finds the cell', async () => {
144+
test('finds the cell', async () => {
143145
const { user } = await setup();
144146

145147
await user.type(await screen.findByRole('textbox', { name: /Search entities/i }), 'Entity 2', {});
@@ -150,9 +152,10 @@ test.skip('finds the cell', async () => {
150152
expect(await screen.findByRole('cell', { name: /Entity 2/i })).toBeInTheDocument();
151153
});
152154

153-
test.skip('opens the modal', async () => {
155+
test('opens the modal', async () => {
154156
const { modalMock, user } = await setup();
155-
await user.click(await screen.findByRole('button', { name: /New Entity/i }));
157+
158+
await user.click(await screen.findByRole('button', { name: /Create New Entity/i }));
156159
expect(modalMock.open).toHaveBeenCalledWith('new entity');
157160

158161
const row = await screen.findByRole('row', {
@@ -164,5 +167,6 @@ test.skip('opens the modal', async () => {
164167
name: /edit/i,
165168
}),
166169
);
167-
await waitFor(() => expect(modalMock.open).toHaveBeenCalledWith('edit entity', 'Entity 2'));
170+
171+
await vi.waitFor(() => expect(modalMock.open).toHaveBeenCalledWith('edit entity', 'Entity 2'));
168172
});

0 commit comments

Comments
 (0)