diff --git a/projects/npm-tools/packages/npm-scripts/src/jest/setup.js b/projects/npm-tools/packages/npm-scripts/src/jest/setup.js index 1a1cc2fd7a..aa3f7ee119 100644 --- a/projects/npm-tools/packages/npm-scripts/src/jest/setup.js +++ b/projects/npm-tools/packages/npm-scripts/src/jest/setup.js @@ -3,10 +3,34 @@ * SPDX-License-Identifier: BSD-3-Clause */ +/* eslint-env browser */ + global.Headers = require('./mocks/Headers'); global.Liferay = require('./mocks/Liferay'); +// Temporary `createRange` mock until we update Jest 26 and jsdom >= 16. +// See: https://github.com/liferay/liferay-frontend-projects/issues/46 + +if (!global.createRange) { + global.createRange = () => ({ + createContextualFragment(htmlString) { + const div = document.createElement('div'); + + div.innerHTML = `
${htmlString}`; + div.removeChild(div.firstChild); + + const fragment = document.createDocumentFragment(); + + while (div.firstChild) { + fragment.appendChild(div.firstChild); + } + + return fragment; + }, + }); +} + global.fetch = require('jest-fetch-mock'); global.themeDisplay = global.Liferay.ThemeDisplay;