// Browser API stubs for jsdom. Tests running in the Node environment (themes.test.js) skip them.
if (typeof window !== 'undefined') {
// jsdom does not implement matchMedia, which Inputmask reads at import time.
if (!window.matchMedia) {
window.matchMedia = (query) => ({
matches: false,
media: query,
onchange: null,
addListener() {},
removeListener() {},
addEventListener() {},
removeEventListener() {},
dispatchEvent: () => false,
});
}
// FilePond checks these at import time and refuses to run without them.
if (!window.URL.createObjectURL) {
window.URL.createObjectURL = () => 'blob:jsdom';
window.URL.revokeObjectURL = () => {};
}
if (!window.CSS?.supports) {
window.CSS = { ...window.CSS, supports: () => true };
}
// jsdom has no canvas backend; axe-core probes it and only needs a null context.
HTMLCanvasElement.prototype.getContext = () => null;
// Under CommonJS (Jest), DataTables 3 no longer sets window.DataTable, while its Buttons
// extension still reads window.DataTable.Buttons. The browser bundle uses the ES module
// builds, which pass DataTable along instead.
if (!window.DataTable) {
window.DataTable = require('datatables.net-bs5');
}
}
|