Skip to content

Commit 5031d72

Browse files
added accessibility checks to angular components
1 parent 8aa5ddf commit 5031d72

File tree

4 files changed

+51
-3
lines changed

4 files changed

+51
-3
lines changed

apps/angular-testing/src/app/app.component.spec.ts

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,8 @@ import { AppComponent, Album } from './app.component';
33
import { AlbumService } from './album.service';
44
import { of } from 'rxjs';
55
import { CUSTOM_ELEMENTS_SCHEMA } from '@angular/core';
6-
6+
import { axe, toHaveNoViolations } from 'jest-axe';
7+
expect.extend(toHaveNoViolations);
78
test('should be able to load albums', async () => {
89
const albums: Album[] = [
910
{
@@ -13,7 +14,7 @@ test('should be able to load albums', async () => {
1314
}
1415
];
1516

16-
await render(AppComponent, {
17+
const { container } = await render(AppComponent, {
1718
componentProviders: [
1819
{
1920
provide: AlbumService,
@@ -30,4 +31,8 @@ test('should be able to load albums', async () => {
3031
fireEvent.click(screen.getByRole('button', { name: /get albums/i }));
3132

3233
await screen.findByText(/sarah/i);
34+
35+
const results = await axe(container)
36+
37+
expect(results).toHaveNoViolations()
3338
});

apps/angular-testing/tsconfig.spec.json

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,14 @@
33
"compilerOptions": {
44
"outDir": "../../dist/out-tsc",
55
"module": "commonjs",
6-
"types": ["jest", "node", "cypress", "@types/testing-library__cypress"]
6+
"types": [
7+
"jest",
8+
"node",
9+
"cypress",
10+
"@types/testing-library__cypress",
11+
"@types/jest-axe",
12+
"jest-axe"
13+
]
714
},
815
"files": ["src/test-setup.ts"],
916
"include": ["**/*.spec.ts", "**/*.d.ts"]

package-lock.json

Lines changed: 34 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -54,12 +54,14 @@
5454
"@testing-library/angular": "^9.5.0",
5555
"@testing-library/cypress": "^6.0.0",
5656
"@types/jest": "25.1.4",
57+
"@types/jest-axe": "^3.2.2",
5758
"@types/node": "~8.9.4",
5859
"axios": "^0.19.2",
5960
"codelyzer": "~5.0.1",
6061
"dotenv": "6.2.0",
6162
"eslint": "6.8.0",
6263
"jest": "25.2.3",
64+
"jest-axe": "^3.4.0",
6365
"jest-pact": "^0.5.4",
6466
"jest-preset-angular": "8.1.2",
6567
"msw": "^0.19.5",

0 commit comments

Comments
 (0)