This repository has been archived by the owner on Jul 12, 2020. It is now read-only.
/
test.js
78 lines (64 loc) · 2.41 KB
/
test.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
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
'use strict';
var test = require('ava');
var a11y = require('../');
process.chdir(__dirname);
function auditsWithHeader(reports, header) {
return reports.audit.filter(function (aud) {
return aud.heading === header;
});
}
test('test that an empty URL fails', function (t) {
t.throws(function () {
a11y('', function () {});
}, /Please supply at least one URL/);
t.end();
});
test('fail if no callback is supplied', function (t) {
t.throws(function () {
a11y('', function () {});
});
t.end();
});
test('test local input generates a report if callback is second param', function (t) {
t.plan(3);
a11y('fixture.html', function (err, reports) {
t.error(err);
var ariaReports = auditsWithHeader(reports, 'ARIA state and property values must be valid');
t.is(ariaReports.length, 1);
t.is(ariaReports[0] && ariaReports[0].result, 'FAIL');
});
});
test('test local input generates a report if callback is third param', function (t) {
t.plan(3);
a11y('fixture.html', null, function (err, reports) {
t.error(err);
var ariaReports = auditsWithHeader(reports, 'ARIA state and property values must be valid');
t.is(ariaReports.length, 1);
t.is(ariaReports[0] && ariaReports[0].result, 'FAIL');
});
});
test('test local input generates a report requiring a delay', function (t) {
t.plan(3);
a11y('fixture.html', {delay: 5}, function (err, reports) {
t.error(err);
var delayReports = auditsWithHeader(reports, 'role=main should only appear on significant elements');
t.is(delayReports.length, 1);
t.is(delayReports[0] && delayReports[0].result, 'FAIL');
});
});
test('test local input generates a verbose report', function (t) {
t.plan(2);
a11y('fixture.html', {verbose: true}, function (err, reports) {
t.error(err);
t.true(reports.report.indexOf('*** Begin accessibility audit results ***') !== -1);
});
});
test('test local input generates a report that includes all failures for a given violation', function (t) {
t.plan(3);
a11y('fixture.html', function (err, reports) {
t.error(err);
var matchingReports = auditsWithHeader(reports, 'This element has an unsupported ARIA attribute');
t.is(matchingReports.length, 1);
t.is(matchingReports[0] && matchingReports[0].elements.match(/\n/g).length, 6);
});
});