Skip to content

Commit

Permalink
(chore) update browser tests
Browse files Browse the repository at this point in the history
  • Loading branch information
joshgoebel committed May 30, 2021
1 parent 1c7c696 commit 0261c45
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 7 deletions.
14 changes: 8 additions & 6 deletions test/browser/highlight_block_callbacks.js
Original file line number Diff line number Diff line change
Expand Up @@ -113,32 +113,34 @@ describe('after:highlightElement', function() {
it('can override language if not originally provided (in class)', async function() {
var test = newTestCase({
code: "anothingstring",
language: ""
language: "java"
});
await buildFakeDOM.bind(this)(test);
this.hljs.addPlugin({
'after:highlightElement': ({el, result}) => {
result.language="basic";
// scan class list and remove other languages
el.classList.remove("language-java");
el.classList.add("language-basic");
}
});

this.hljs.highlightElement(this.block);
should(this.block.outerHTML.includes(`class="hljs language-basic"`)).equal(true);
should(this.block.className).equal(`hljs language-basic`);

})
it('can modify result and affect the render output', async function() {
it('can modify element after render', async function() {
var test = newTestCase({
code: "var a = 4;",
language: "javascript"
})
await buildFakeDOM.bind(this)(test);
this.hljs.addPlugin({
'after:highlightElement': ({el, result}) => {
result.value="redacted";
el.innerHTML = "redacted";
}
});

this.hljs.highlightElement(this.block);
this.block.outerHTML.should.equal(`<code class="javascript hljs language-javascript">redacted</code>`);
this.block.outerHTML.should.equal(`<code class="language-javascript hljs">redacted</code>`);
})
})
2 changes: 1 addition & 1 deletion test/browser/test_case.js
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ function newTestCase(opts) {
test.html = opts.html;
test.expect = opts.expect;
test.language = opts.language;
test.html = test.html || `<pre><code class='${test.language}'>${test.code}</code></pre>`;
test.html = test.html || `<pre><code class='language-${test.language}'>${test.code}</code></pre>`;
test.runner = async function() {
await buildFakeDOM.bind(this, test)();
this.hljs.highlightElement(this.block);
Expand Down

0 comments on commit 0261c45

Please sign in to comment.