diff --git a/jest.config.ts b/jest.config.ts index a9cad47a7..027a51f74 100644 --- a/jest.config.ts +++ b/jest.config.ts @@ -2,7 +2,7 @@ export default { roots: ['/src'], collectCoverageFrom: ['src/**/*.{js,jsx,ts,tsx}', '!src/**/*.d.ts'], setupFiles: ['react-app-polyfill/jsdom'], - setupFilesAfterEnv: [], + setupFilesAfterEnv: ['./jest.setup.ts'], testMatch: [ '/src/**/__tests__/**/*.{js,jsx,ts,tsx}', '/src/**/*.{spec,test}.{js,jsx,ts,tsx}', diff --git a/jest.setup.ts b/jest.setup.ts new file mode 100644 index 000000000..76140ff0b --- /dev/null +++ b/jest.setup.ts @@ -0,0 +1,30 @@ +// react-intl +import intl from 'react-intl-universal'; +require('intl/locale-data/jsonp/en.js'); + +const locales = require('./src/locales/index'); +const { LANG } = require('./src/common/constants'); +intl.init({ locales: { [LANG.EN]: locales.default.en }, currentLocale: LANG.EN }); + +// matchmedia fix +Object.defineProperty(window, 'matchMedia', { + value: jest.fn().mockImplementation((query) => ({ + // deprecated + addEventListener: jest.fn(), + + addListener: jest.fn(), + + dispatchEvent: jest.fn(), + + matches: false, + + media: query, + + onchange: null, + + removeEventListener: jest.fn(), + // deprecated + removeListener: jest.fn(), + })), + writable: true, +});