diff --git a/package.json b/package.json index b62e6166..04e642cd 100644 --- a/package.json +++ b/package.json @@ -91,7 +91,7 @@ "@storybook/addon-actions": "^5.3.6", "@storybook/addon-links": "^5.3.6", "@storybook/react": "^5.3.6", - "@testing-library/dom": "^7.24.1", + "@testing-library/dom": "^8.0.0", "@testing-library/jest-dom": "^5.11.1", "@testing-library/react": "^12.0.0", "@types/common-tags": "^1.8.0", diff --git a/packages/netlify-cms-media-library-cloudinary/src/__tests__/index.spec.js b/packages/netlify-cms-media-library-cloudinary/src/__tests__/index.spec.js index d19038cb..b1d0f658 100644 --- a/packages/netlify-cms-media-library-cloudinary/src/__tests__/index.spec.js +++ b/packages/netlify-cms-media-library-cloudinary/src/__tests__/index.spec.js @@ -1,10 +1,20 @@ -import { queryHelpers, waitForElement } from '@testing-library/dom'; - import cloudinary from '../index'; +jest.mock('netlify-cms-lib-util'); + +describe('cloudinary exports', () => { + it('exports an object with expected properties', () => { + expect(cloudinary).toMatchInlineSnapshot(` + Object { + "init": [Function], + "name": "cloudinary", + } + `); + }); +}); + describe('cloudinary media library', () => { let mediaLibrary; - let cloudinaryScript; let cloudinaryConfig; let cloudinaryInsertHandler; @@ -28,37 +38,16 @@ describe('cloudinary media library', () => { show: jest.fn(), hide: jest.fn(), }; + }); - /** - * We load the Cloudinary library by injecting a script tag to the page - * head. Initialization waits for the script to load, so here we fake it. - * This also tests that the expected script is added to the DOM. - */ - waitForElement(() => { - const url = 'https://media-library.cloudinary.com/global/all.js'; - return queryHelpers.queryByAttribute('src', document, url); - }).then(script => { - cloudinaryScript = script; - script.onreadystatechange(); - }); + beforeEach(() => { + jest.clearAllMocks(); }); afterEach(() => { - /** - * Remove the script element from the dom after each test. - */ - if (cloudinaryScript) { - document.head.removeChild(cloudinaryScript); - } - }); - - it('exports an object with expected properties', () => { - expect(cloudinary).toMatchInlineSnapshot(` -Object { - "init": [Function], - "name": "cloudinary", -} -`); + const { loadScript } = require('netlify-cms-lib-util'); + expect(loadScript).toHaveBeenCalledTimes(1); + expect(loadScript).toHaveBeenCalledWith('https://media-library.cloudinary.com/global/all.js'); }); describe('configuration', () => { diff --git a/yarn.lock b/yarn.lock index 0b8a201c..a29f2f64 100644 --- a/yarn.lock +++ b/yarn.lock @@ -3205,20 +3205,6 @@ dependencies: defer-to-connect "^1.0.1" -"@testing-library/dom@^7.24.1": - version "7.31.2" - resolved "https://registry.yarnpkg.com/@testing-library/dom/-/dom-7.31.2.tgz#df361db38f5212b88555068ab8119f5d841a8c4a" - integrity sha512-3UqjCpey6HiTZT92vODYLPxTBWlM8ZOOjr3LX5F37/VRipW2M1kX6I/Cm4VXzteZqfGfagg8yXywpcOgQBlNsQ== - dependencies: - "@babel/code-frame" "^7.10.4" - "@babel/runtime" "^7.12.5" - "@types/aria-query" "^4.2.0" - aria-query "^4.2.2" - chalk "^4.1.0" - dom-accessibility-api "^0.5.6" - lz-string "^1.4.4" - pretty-format "^26.6.2" - "@testing-library/dom@^8.0.0": version "8.0.0" resolved "https://registry.yarnpkg.com/@testing-library/dom/-/dom-8.0.0.tgz#2bb994393c566aae021db86dd263ba06e8b71b38"