Skip to content

Commit

Permalink
Merge pull request #234 from bryceosterhaus/master
Browse files Browse the repository at this point in the history
feat(npm-scripts): add jest mock for createRange and createContextualFragment
  • Loading branch information
wincent authored Nov 12, 2020
2 parents d4c6304 + 4fa6e9a commit 32b5848
Showing 1 changed file with 24 additions and 0 deletions.
24 changes: 24 additions & 0 deletions projects/npm-tools/packages/npm-scripts/src/jest/setup.js
Original file line number Diff line number Diff line change
Expand Up @@ -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 = `<br>${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;

0 comments on commit 32b5848

Please sign in to comment.