mirror of
https://github.com/nocobase/nocobase
synced 2024-11-15 14:46:13 +00:00
49117afb72
* refactor: front-end testing with vitest * fix: fix build failed
25 lines
861 B
TypeScript
25 lines
861 B
TypeScript
import '@testing-library/jest-dom';
|
||
import { vi } from 'vitest';
|
||
import '../packages/core/client/src/i18n';
|
||
|
||
// 解决 ypeError: window.matchMedia is not a function
|
||
// 参见: https://github.com/vitest-dev/vitest/issues/821#issuecomment-1046954558
|
||
Object.defineProperty(window, 'matchMedia', {
|
||
writable: true,
|
||
value: vi.fn().mockImplementation((query) => ({
|
||
matches: false,
|
||
media: query,
|
||
onchange: null,
|
||
addListener: vi.fn(), // deprecated
|
||
removeListener: vi.fn(), // deprecated
|
||
addEventListener: vi.fn(),
|
||
removeEventListener: vi.fn(),
|
||
dispatchEvent: vi.fn(),
|
||
})),
|
||
});
|
||
|
||
// 解决 Error: Not implemented: window.computedStyle(elt, pseudoElt)
|
||
// 参见:https://github.com/nickcolley/jest-axe/issues/147#issuecomment-758804533
|
||
const { getComputedStyle } = window;
|
||
window.getComputedStyle = (elt) => getComputedStyle(elt);
|