forked from nodejs/nodejs.dev
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtest-utils.js
32 lines (26 loc) · 917 Bytes
/
test-utils.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
import React from 'react';
import { render as rtlRender } from '@testing-library/react';
import { IntlProvider } from 'react-intl';
import fs from 'fs';
const messages = JSON.parse(
fs.readFileSync('src/i18n/locales/en.json', 'utf8')
);
// ICU configuration for React-Intl
Intl.NumberFormat.format = new Intl.NumberFormat('en').format;
Intl.DateTimeFormat.format = new Intl.DateTimeFormat('en').format;
function render(ui, { locale = 'en', ...renderOptions } = {}) {
// eslint-disable-next-line react/prop-types
function Wrapper({ children }) {
return (
// eslint-disable-next-line react/jsx-filename-extension
<IntlProvider locale={locale} messages={messages}>
{children}
</IntlProvider>
);
}
return rtlRender(ui, { wrapper: Wrapper, ...renderOptions });
}
// re-export everything
export * from '@testing-library/react';
// override render method
export { render };