0
Fork 0
mirror of https://github.com/logto-io/logto.git synced 2024-12-16 20:26:19 -05:00

chore(ui): add patch to matchMedia

This commit is contained in:
Gao Sun 2021-08-02 23:45:55 +08:00
parent a245f5f1e6
commit 2f47ae28b7
No known key found for this signature in database
GPG key ID: 0F0EFA2E36639F31
4 changed files with 22 additions and 4 deletions

View file

@ -26,6 +26,7 @@ module.exports = {
'^.+\\.(css|less|scss)$': 'babel-jest',
'@/(.*)': '<rootDir>/src/$1',
};
config.setupFilesAfterEnv = [...config.setupFilesAfterEnv, './src/jest.setup.ts'];
return config;
},

View file

@ -8,7 +8,7 @@ import SignIn from './pages/SignIn';
import Register from './pages/Register';
import './scss/normalized.scss';
initI18n();
void initI18n();
const App = () => {
const theme = useTheme();

View file

@ -3,8 +3,8 @@ import LanguageDetector from 'i18next-browser-languagedetector';
import { initReactI18next } from 'react-i18next';
import resources from '@logto/phrases';
const initI18n = () => {
void i18n
const initI18n = async () =>
i18n
.use(initReactI18next)
.use(LanguageDetector)
.init({
@ -14,6 +14,5 @@ const initI18n = () => {
escapeValue: false,
},
});
};
export default initI18n;

View file

@ -0,0 +1,18 @@
// https://jestjs.io/docs/manual-mocks#mocking-methods-which-are-not-implemented-in-jsdom
Object.defineProperty(window, 'matchMedia', {
writable: true,
value: jest.fn().mockImplementation((query) => ({
matches: false,
// eslint-disable-next-line @typescript-eslint/no-unsafe-assignment
media: query,
onchange: null,
addListener: jest.fn(), // Deprecated
removeListener: jest.fn(), // Deprecated
addEventListener: jest.fn(),
removeEventListener: jest.fn(),
dispatchEvent: jest.fn(),
})),
});
export {};