Mock range api globally

This commit is contained in:
Mark Kaylor 2023-01-30 11:54:39 +01:00
parent 67750e0f82
commit 5a5a2666b1
4 changed files with 17 additions and 15 deletions

View File

@ -46,6 +46,7 @@ module.exports = {
'<rootDir>/packages/admin-test-utils/lib/mocks/IntersectionObserver.js',
'<rootDir>/packages/admin-test-utils/lib/mocks/ResizeObserver.js',
'<rootDir>/packages/admin-test-utils/lib/mocks/windowMatchMedia.js',
'<rootDir>/packages/admin-test-utils/lib/mocks/mockRangeApi.js',
],
setupFilesAfterEnv: [
'<rootDir>/packages/admin-test-utils/lib/setup/styled-components.js',

View File

@ -0,0 +1,16 @@
/* eslint-disable no-undef */
'use strict';
// Codemirror inner dependency, reference: https://github.com/jsdom/jsdom/issues/3002
// Otherwise it throws: TypeError: range(...).getBoundingClientRect is not a function
document.createRange = () => {
const range = new Range();
range.getClientRects = jest.fn(() => ({
item: () => null,
length: 0,
}));
return range;
};

View File

@ -16,18 +16,6 @@ const user = userEvent.setup();
jest.mock('../hooks/useAuditLogsData', () => jest.fn());
// Codemirror inner dependency, reference: https://github.com/jsdom/jsdom/issues/3002
// Otherwise it throws: TypeError: range(...).getBoundingClientRect is not a function
document.createRange = () => {
const range = new Range();
range.getClientRects = jest.fn(() => ({
item: () => null,
length: 0,
}));
return range;
};
const mockUseQuery = jest.fn();
jest.mock('react-query', () => {
const actual = jest.requireActual('react-query');

View File

@ -34,9 +34,6 @@ export const getDefaultMessage = (value) => {
};
export const getActionMessage = (message, action) => {
console.log('message', message);
console.log('action', action);
if (message.includes('entry')) {
return `${message} (${action.model})`;
}