From a7b3560714b4d9cc4ab32dffcd1f74a284b93580 Mon Sep 17 00:00:00 2001 From: GitLab Bot Date: Fri, 18 Feb 2022 09:45:46 +0000 Subject: Add latest changes from gitlab-org/gitlab@14-8-stable-ee --- spec/frontend/behaviors/copy_as_gfm_spec.js | 37 +++++++++++------------------ 1 file changed, 14 insertions(+), 23 deletions(-) (limited to 'spec/frontend/behaviors/copy_as_gfm_spec.js') diff --git a/spec/frontend/behaviors/copy_as_gfm_spec.js b/spec/frontend/behaviors/copy_as_gfm_spec.js index 557b609f5f9..c96db09cc76 100644 --- a/spec/frontend/behaviors/copy_as_gfm_spec.js +++ b/spec/frontend/behaviors/copy_as_gfm_spec.js @@ -1,3 +1,4 @@ +import waitForPromises from 'helpers/wait_for_promises'; import initCopyAsGFM, { CopyAsGFM } from '~/behaviors/markdown/copy_as_gfm'; describe('CopyAsGFM', () => { @@ -81,49 +82,40 @@ describe('CopyAsGFM', () => { stopPropagation() {}, }; CopyAsGFM.copyAsGFM(e, CopyAsGFM.transformGFMSelection); - return clipboardData; + + return waitForPromises(); }; - beforeAll((done) => { + beforeAll(() => { initCopyAsGFM(); // Fake call to nodeToGfm so the import of lazy bundle happened - CopyAsGFM.nodeToGFM(document.createElement('div')) - .then(() => { - done(); - }) - .catch(done.fail); + return CopyAsGFM.nodeToGFM(document.createElement('div')); }); beforeEach(() => jest.spyOn(clipboardData, 'setData')); describe('list handling', () => { - it('uses correct gfm for unordered lists', (done) => { + it('uses correct gfm for unordered lists', async () => { const selection = stubSelection('
  • List Item1
  • List Item2
  • \n', 'UL'); window.getSelection = jest.fn(() => selection); - simulateCopy(); + await simulateCopy(); - setImmediate(() => { - const expectedGFM = '* List Item1\n* List Item2'; + const expectedGFM = '* List Item1\n* List Item2'; - expect(clipboardData.setData).toHaveBeenCalledWith('text/x-gfm', expectedGFM); - done(); - }); + expect(clipboardData.setData).toHaveBeenCalledWith('text/x-gfm', expectedGFM); }); - it('uses correct gfm for ordered lists', (done) => { + it('uses correct gfm for ordered lists', async () => { const selection = stubSelection('
  • List Item1
  • List Item2
  • \n', 'OL'); window.getSelection = jest.fn(() => selection); - simulateCopy(); + await simulateCopy(); - setImmediate(() => { - const expectedGFM = '1. List Item1\n1. List Item2'; + const expectedGFM = '1. List Item1\n1. List Item2'; - expect(clipboardData.setData).toHaveBeenCalledWith('text/x-gfm', expectedGFM); - done(); - }); + expect(clipboardData.setData).toHaveBeenCalledWith('text/x-gfm', expectedGFM); }); }); }); @@ -131,10 +123,9 @@ describe('CopyAsGFM', () => { describe('CopyAsGFM.quoted', () => { const sampleGFM = '* List 1\n* List 2\n\n`Some code`'; - it('adds quote char `> ` to each line', (done) => { + it('adds quote char `> ` to each line', () => { const expectedQuotedGFM = '> * List 1\n> * List 2\n> \n> `Some code`'; expect(CopyAsGFM.quoted(sampleGFM)).toEqual(expectedQuotedGFM); - done(); }); }); }); -- cgit v1.2.3