Skip to content

Commit 1a03dc6

Browse files
authored
docs: fix example tests (#4564)
When I updated #4548 to latest it caused the qunit tests to fail. Turns out that [qunitjs](https://www.npmjs.com/package/qunitjs) has been deprecated and is now called just `qunit`, and `grunt-contrib-qunit` [has issues](gruntjs/grunt-contrib-qunit#209) if not using latest qunit. Once upgraded I was able to get the tests passing but only in headed mode. That was because puppeteer [is now headless by default](https://github.com/gruntjs/grunt-contrib-qunit/blob/main/docs/qunit-options.md#puppeteer), so passing the `ignoreDefaultArgs` param and the `--headless` arg was causing the issue. `jest_react` was also failing and after trying to fix it with it's current dependencies @dbjorge suggested it would be better to just change it over to `@react/testing-library`. It also means we can support react 18 in the examples too.
1 parent 4d8c87e commit 1a03dc6

File tree

6 files changed

+20
-37
lines changed

6 files changed

+20
-37
lines changed

doc/examples/jest_react/jest.setup.js

Lines changed: 0 additions & 4 deletions
This file was deleted.

doc/examples/jest_react/link.test.js

Lines changed: 4 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,12 @@
11
import React from 'react';
2-
import { mount, render } from 'enzyme';
2+
import { render } from '@testing-library/react';
33
import axe from 'axe-core';
44

55
import Link from './link';
66

77
test('Link has no axe violations', done => {
8-
const fixture = document.createElement('div');
9-
document.body.appendChild(fixture);
10-
11-
const linkComponent = mount(
12-
<Link page="http://www.axe-core.org">axe website</Link>,
13-
{ attachTo: fixture }
8+
const { container } = render(
9+
<Link page="http://www.axe-core.org">axe website</Link>
1410
);
1511

1612
const config = {
@@ -19,7 +15,7 @@ test('Link has no axe violations', done => {
1915
'link-in-text-block': { enabled: false }
2016
}
2117
};
22-
axe.run(fixture, config, (err, { violations }) => {
18+
axe.run(container, config, (err, { violations }) => {
2319
expect(err).toBe(null);
2420
expect(violations).toHaveLength(0);
2521
done();

doc/examples/jest_react/package.json

Lines changed: 9 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -12,20 +12,16 @@
1212
"test": "jest"
1313
},
1414
"devDependencies": {
15-
"@babel/preset-env": "^7.20.2",
16-
"@babel/preset-react": "^7.18.6",
17-
"@wojtekmaj/enzyme-adapter-react-17": "^0.8.0",
18-
"axe-core": "^4.6.2",
19-
"enzyme": "^3.11.0",
20-
"jest": "^29.3.1",
21-
"jest-environment-jsdom": "^29.3.1",
22-
"react": "^17.0.2",
23-
"react-dom": "^17.0.2"
15+
"@babel/preset-env": "^7.25.3",
16+
"@babel/preset-react": "^7.24.7",
17+
"@testing-library/jest-dom": "^6.4.8",
18+
"@testing-library/react": "^16.0.0",
19+
"jest": "^29.7.0",
20+
"jest-environment-jsdom": "^29.7.0",
21+
"react": "^18.3.1",
22+
"react-dom": "^18.3.1"
2423
},
2524
"jest": {
26-
"testEnvironment": "jsdom",
27-
"setupFilesAfterEnv": [
28-
"<rootDir>/jest.setup.js"
29-
]
25+
"testEnvironment": "jsdom"
3026
}
3127
}

doc/examples/qunit/Gruntfile.js

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -8,12 +8,7 @@ module.exports = function (grunt) {
88
all: ['test/**/*.html'],
99
options: {
1010
puppeteer: {
11-
ignoreDefaultArgs: true,
12-
args: [
13-
'--headless',
14-
'--disable-web-security',
15-
'--allow-file-access-from-files'
16-
]
11+
args: ['--disable-web-security', '--allow-file-access-from-files']
1712
},
1813
timeout: 10000
1914
}

doc/examples/qunit/package.json

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -13,9 +13,9 @@
1313
},
1414
"devDependencies": {
1515
"axe-core": "^4.6.2",
16-
"grunt": "^1.5.3",
17-
"grunt-contrib-qunit": "^5.1.1",
18-
"puppeteer": "^19.5.0",
19-
"qunitjs": "^2.0.1"
16+
"grunt": "^1.6.1",
17+
"grunt-contrib-qunit": "^10.1.1",
18+
"puppeteer": "^23.1.0",
19+
"qunit": "^2.22.0"
2020
}
2121
}

doc/examples/qunit/test/test.html

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,10 +6,10 @@
66
<!-- Load local QUnit. -->
77
<link
88
rel="stylesheet"
9-
href="../node_modules/qunitjs/qunit/qunit.css"
9+
href="../node_modules/qunit/qunit/qunit.css"
1010
media="screen"
1111
/>
12-
<script src="../node_modules/qunitjs/qunit/qunit.js"></script>
12+
<script src="../node_modules/qunit/qunit/qunit.js"></script>
1313
<!-- Load local lib and tests. -->
1414
<script src="../node_modules/axe-core/axe.min.js"></script>
1515
<script src="a11y.js"></script>

0 commit comments

Comments
 (0)