-
Notifications
You must be signed in to change notification settings - Fork 2
/
chai.js
53 lines (39 loc) · 1.16 KB
/
chai.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
import { use } from 'chai';
import chaiDom from 'chai-dom';
function importAxe() {
return new Promise((resolve, reject) => {
const axeScript = document.createElement('script');
axeScript.src = 'https://unpkg.com/axe-core@4.1.4/axe.js';
axeScript.onload = () => {
if (window.axe) {
resolve();
} else {
reject(new Error(`window.axe is ${window.axe}`));
}
};
document.head.appendChild(axeScript);
});
}
function importChaiA11y() {
return new Promise((resolve, reject) => {
const chaiA11yScript = document.createElement('script');
chaiA11yScript.type = 'module';
chaiA11yScript.innerHTML = `
import { chaiA11yAxe } from "https://unpkg.com/chai-a11y-axe@1.3.1/index.js";
window.chaiA11yAxe = chaiA11yAxe
`;
chaiA11yScript.onload = () => {
if (window.chaiA11yAxe) {
resolve();
} else {
reject(new Error(`window.chaiA11yAxe is ${window.chaiA11yAxe}`));
}
};
document.head.appendChild(chaiA11yScript);
});
}
export default async function loadChai() {
await importAxe();
await importChaiA11y();
return use(window.chaiA11yAxe).use(chaiDom);
}