-
-
Notifications
You must be signed in to change notification settings - Fork 374
/
highlight-spec.js
82 lines (77 loc) · 2.34 KB
/
highlight-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
71
72
73
74
75
76
77
78
79
80
81
82
"use strict";
describe("Core — Highlight", function() {
afterAll(done => {
flushIframes();
done();
});
it("shouldn't highlight idl blocks", done => {
var ops = {
config: makeBasicConfig(),
body: makeDefaultBody() + `
<section><pre class=idl>
[Constructor]interface Dahut : Mammal {
const unsigned short DEXTROGYROUS = 1;
Dahut turnAround(float angle, boolean fall);
};</pre>
</section>`
};
makeRSDoc(ops, function(doc) {
var pre = doc.querySelector("pre");
expect(pre.classList.contains("hljs")).toBeFalsy();
expect(pre.querySelectorAll("span[class^=hljs-]").length).toBe(0);
}).then(done);
});
it("should automatically highlight", done => {
var ops = {
config: makeBasicConfig(),
body: makeDefaultBody() +
`<section>
<pre class=example>
function foo() {
alert('foo');
}
</pre>
</section>`
};
makeRSDoc(ops, function(doc) {
var pre = doc.querySelector("div.example pre");
expect(pre.classList.contains("hljs")).toBeTruthy();
expect(pre.querySelectorAll("span[class^=hljs-]").length).toBeGreaterThan(0);
}).then(done);
});
it("shouldn't highlight pre elements when told not to", done => {
var ops = {
config: makeBasicConfig(),
body: makeDefaultBody() +
`<section>
<pre class='nohighlight example'>
function foo() {
alert('foo');
}
</pre>
</section>`
};
makeRSDoc(ops, function(doc) {
var pre = doc.querySelector("div.example pre");
expect(pre.classList.contains("nohighlight")).toBeTruthy();
expect(pre.querySelectorAll("span[class^=hljs-]").length).toBe(0);
}).then(done);
});
it("should respect the noHighlightCSS by not highlighting anything", done => {
var ops = {
config: Object.assign(makeBasicConfig(), { noHighlightCSS: true }),
body: makeDefaultBody() +
`<section>
<pre id="test">
function foo() {
alert('foo');
}
</pre>
</section>`
};
makeRSDoc(ops, function(doc) {
var pre = doc.querySelector("#test");
expect(pre.querySelectorAll("span[class^=hljs-]").length).toBe(0);
}).then(done);
});
});