mirror of
https://gitee.com/nocobase/nocobase.git
synced 2024-12-05 13:47:45 +08: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);
|