diff options
author | GitLab Bot <gitlab-bot@gitlab.com> | 2021-08-19 09:08:42 +0000 |
---|---|---|
committer | GitLab Bot <gitlab-bot@gitlab.com> | 2021-08-19 09:08:42 +0000 |
commit | b76ae638462ab0f673e5915986070518dd3f9ad3 (patch) | |
tree | bdab0533383b52873be0ec0eb4d3c66598ff8b91 /spec/frontend/syntax_highlight_spec.js | |
parent | 434373eabe7b4be9593d18a585fb763f1e5f1a6f (diff) | |
download | gitlab-ce-14.2.0-rc42.tar.gz |
Add latest changes from gitlab-org/gitlab@14-2-stable-eev14.2.0-rc42
Diffstat (limited to 'spec/frontend/syntax_highlight_spec.js')
-rw-r--r-- | spec/frontend/syntax_highlight_spec.js | 63 |
1 files changed, 37 insertions, 26 deletions
diff --git a/spec/frontend/syntax_highlight_spec.js b/spec/frontend/syntax_highlight_spec.js index 418679e7d18..8ad4f8d5c70 100644 --- a/spec/frontend/syntax_highlight_spec.js +++ b/spec/frontend/syntax_highlight_spec.js @@ -10,39 +10,50 @@ describe('Syntax Highlighter', () => { } return (window.gon.user_color_scheme = value); }; - describe('on a js-syntax-highlight element', () => { - beforeEach(() => { - setFixtures('<div class="js-syntax-highlight"></div>'); - }); - - it('applies syntax highlighting', () => { - stubUserColorScheme('monokai'); - syntaxHighlight($('.js-syntax-highlight')); - expect($('.js-syntax-highlight')).toHaveClass('monokai'); + // We have to bind `document.querySelectorAll` to `document` to not mess up the fn's context + describe.each` + desc | fn + ${'jquery'} | ${$} + ${'vanilla all'} | ${document.querySelectorAll.bind(document)} + ${'vanilla single'} | ${document.querySelector.bind(document)} + `('highlight using $desc syntax', ({ fn }) => { + describe('on a js-syntax-highlight element', () => { + beforeEach(() => { + setFixtures('<div class="js-syntax-highlight"></div>'); + }); + + it('applies syntax highlighting', () => { + stubUserColorScheme('monokai'); + syntaxHighlight(fn('.js-syntax-highlight')); + + expect(fn('.js-syntax-highlight')).toHaveClass('monokai'); + }); }); - }); - describe('on a parent element', () => { - beforeEach(() => { - setFixtures( - '<div class="parent">\n <div class="js-syntax-highlight"></div>\n <div class="foo"></div>\n <div class="js-syntax-highlight"></div>\n</div>', - ); - }); + describe('on a parent element', () => { + beforeEach(() => { + setFixtures( + '<div class="parent">\n <div class="js-syntax-highlight"></div>\n <div class="foo"></div>\n <div class="js-syntax-highlight"></div>\n</div>', + ); + }); - it('applies highlighting to all applicable children', () => { - stubUserColorScheme('monokai'); - syntaxHighlight($('.parent')); + it('applies highlighting to all applicable children', () => { + stubUserColorScheme('monokai'); + syntaxHighlight(fn('.parent')); - expect($('.parent, .foo')).not.toHaveClass('monokai'); - expect($('.monokai').length).toBe(2); - }); + expect(fn('.parent')).not.toHaveClass('monokai'); + expect(fn('.foo')).not.toHaveClass('monokai'); + + expect(document.querySelectorAll('.monokai').length).toBe(2); + }); - it('prevents an infinite loop when no matches exist', () => { - setFixtures('<div></div>'); - const highlight = () => syntaxHighlight($('div')); + it('prevents an infinite loop when no matches exist', () => { + setFixtures('<div></div>'); + const highlight = () => syntaxHighlight(fn('div')); - expect(highlight).not.toThrow(); + expect(highlight).not.toThrow(); + }); }); }); }); |