diff options
author | GitLab Bot <gitlab-bot@gitlab.com> | 2022-09-20 02:18:09 +0300 |
---|---|---|
committer | GitLab Bot <gitlab-bot@gitlab.com> | 2022-09-20 02:18:09 +0300 |
commit | 6ed4ec3e0b1340f96b7c043ef51d1b33bbe85fde (patch) | |
tree | dc4d20fe6064752c0bd323187252c77e0a89144b /spec/frontend/vue_shared/components/code_block_highlighted_spec.js | |
parent | 9868dae7fc0655bd7ce4a6887d4e6d487690eeed (diff) |
Add latest changes from gitlab-org/gitlab@15-4-stable-eev15.4.0-rc42
Diffstat (limited to 'spec/frontend/vue_shared/components/code_block_highlighted_spec.js')
-rw-r--r-- | spec/frontend/vue_shared/components/code_block_highlighted_spec.js | 65 |
1 files changed, 65 insertions, 0 deletions
diff --git a/spec/frontend/vue_shared/components/code_block_highlighted_spec.js b/spec/frontend/vue_shared/components/code_block_highlighted_spec.js new file mode 100644 index 00000000000..181692e61b5 --- /dev/null +++ b/spec/frontend/vue_shared/components/code_block_highlighted_spec.js @@ -0,0 +1,65 @@ +import { shallowMount } from '@vue/test-utils'; +import CodeBlock from '~/vue_shared/components/code_block_highlighted.vue'; +import waitForPromises from 'helpers/wait_for_promises'; + +describe('Code Block Highlighted', () => { + let wrapper; + + const code = 'const foo = 1;'; + + const createComponent = (propsData = {}) => { + wrapper = shallowMount(CodeBlock, { propsData }); + }; + + afterEach(() => { + wrapper.destroy(); + }); + + it('renders highlighted code if language is supported', async () => { + createComponent({ code, language: 'javascript' }); + + await waitForPromises(); + + expect(wrapper.element).toMatchInlineSnapshot(` + <code-block-stub + class="highlight" + code="" + maxheight="initial" + > + <span> + <span + class="hljs-keyword" + > + const + </span> + foo = + <span + class="hljs-number" + > + 1 + </span> + ; + </span> + </code-block-stub> + `); + }); + + it("renders plain text if language isn't supported", async () => { + createComponent({ code, language: 'foobar' }); + await waitForPromises(); + + expect(wrapper.emitted('error')).toEqual([[expect.any(TypeError)]]); + + expect(wrapper.element).toMatchInlineSnapshot(` + <code-block-stub + class="highlight" + code="" + maxheight="initial" + > + <span> + const foo = 1; + </span> + </code-block-stub> + `); + }); +}); |