mock useIntl methods to solve issue with the unicode space character in the snapshot tests

This commit is contained in:
Simone Taeggi 2023-01-13 18:50:50 +01:00
parent d1cb57f422
commit 356c13e397
2 changed files with 45 additions and 0 deletions

View File

@ -37,6 +37,21 @@ jest.spyOn(axiosInstance, 'get').mockResolvedValue({
jest.spyOn(Date, 'now').mockImplementation(() => new Date('2015-10-01T08:00:00.000Z'));
jest.mock('react-intl', () => {
const reactIntl = jest.requireActual('react-intl');
const intl = reactIntl.createIntl({
locale: 'en',
});
intl.formatDate = jest.fn(() => '11/15/2021');
intl.formatTime = jest.fn(() => '12:00 AM');
return {
...reactIntl,
useIntl: () => intl,
};
});
const client = new QueryClient({
defaultOptions: {
queries: {

View File

@ -13,6 +13,36 @@ import { createMemoryHistory } from 'history';
import qs from 'qs';
import FilterListURLQuery from '../index';
jest.mock('react-intl', () => {
const reactIntl = jest.requireActual('react-intl');
const intl = reactIntl.createIntl({
locale: 'en',
messages: {
'components.FilterOptions.FILTER_TYPES.$eq': 'is',
'components.FilterOptions.FILTER_TYPES.$ne': 'is not',
'components.FilterOptions.FILTER_TYPES.$contains': 'contains (case sensitive)',
'components.FilterOptions.FILTER_TYPES.$notContains': 'does not contain (case sensitive)',
'components.FilterOptions.FILTER_TYPES.$gt': 'is greater than',
'components.FilterOptions.FILTER_TYPES.$gte': 'is greater than or equal to',
'components.FilterOptions.FILTER_TYPES.$lt': 'is lower than',
'components.FilterOptions.FILTER_TYPES.$lte': 'is lower than or equal to',
'components.FilterOptions.FILTER_TYPES.$startsWith': 'starts with',
'components.FilterOptions.FILTER_TYPES.$endsWith': 'ends with',
'components.FilterOptions.FILTER_TYPES.$null': 'is null',
'components.FilterOptions.FILTER_TYPES.$notNull': 'is not null',
},
textComponent: 'span',
});
intl.formatDate = jest.fn(() => 'Wednesday, September 1, 2021');
intl.formatTime = jest.fn(() => '12:45 AM');
return {
...reactIntl,
useIntl: () => intl,
};
});
const makeApp = (history, filtersSchema) => (
<Router history={history}>
<ThemeProvider theme={lightTheme}>