This repository has been archived by the owner on Jun 7, 2024. It is now read-only.
forked from speced/respec
-
Notifications
You must be signed in to change notification settings - Fork 0
/
no-headingless-sections-spec.js
70 lines (70 loc) · 2.16 KB
/
no-headingless-sections-spec.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
"use strict";
describe("Core Linter Rule - 'no-headingless-sections'", () => {
const ruleName = "no-headingless-sections";
const config = {
lint: { [ruleName]: true },
};
let rule;
beforeAll(async () => {
rule = await new Promise(resolve => {
require([`core/linter-rules/${ruleName}`], ({ rule }) => resolve(rule));
});
});
const doc = document.implementation.createHTMLDocument("test doc");
beforeEach(() => {
// Make sure every unordered test get an empty document
// See: https://github.com/w3c/respec/pull/1495
while (doc.body.firstChild) {
doc.body.removeChild(doc.body.firstChild);
}
});
it("returns error when heading is missing section", async () => {
const section = doc.createElement("section");
doc.body.appendChild(section);
const results = await rule.lint(config, doc);
expect(results.length).toEqual(1);
const result = results[0];
expect(result).toEqual({
name: ruleName,
offendingElements: [section],
occurrences: 1,
description: "All sections must start with a `h2-6` element.",
howToFix: "Add a `h2-6` to the offending section or use a `<div>`.",
help: "See developer console.",
});
section.remove();
});
it("doesn't complain when sections do have a heading", async () => {
doc.body.innerHTML = `
<section>
<h2>test</h2>
<section>
<h3>Test</h3>
</section>
<section>
<h3>Test</h3>
</section>
</section>
`;
const results = await rule.lint(config, doc);
expect(results.length).toEqual(0);
});
it("complains when a nested section doesn't have a heading", async () => {
doc.body.innerHTML = `
<section>
<h2>test</h2>
<section>
<h3>Test</h3>
</section>
<section id="badone">
<p></p>
</section>
</section>
`;
const badone = doc.getElementById("badone");
const results = await rule.lint(config, doc);
const [result] = results;
expect(result.offendingElements.length).toEqual(1);
expect(result.offendingElements[0]).toEqual(badone);
});
});