forked from opencollective/opencollective-frontend
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathsnapshot-helpers.js
31 lines (28 loc) · 1.03 KB
/
snapshot-helpers.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
import React from 'react';
import { IntlProvider } from 'react-intl';
import renderer from 'react-test-renderer';
import { withRequiredProviders } from './providers';
/**
* A helper to:
* 1. Wrap component under all required OC's providers
* 2. Render the tree
* 3. Compare with snapshot
*
* @param {ReactNode} component - the component to render
* @param {Object} providerParams - parameters to give to the providers:
* - IntlProvider: { locale }
* - ThemeProvider: { theme }
*/
export const snapshot = (component, providersParams = {}) => {
const componentWithProviders = withRequiredProviders(component, providersParams);
const tree = renderer.create(componentWithProviders).toJSON();
return expect(tree).toMatchSnapshot();
};
/**
* @deprecated Use `snapshot`
* Same as `snapshot` but wraps component in a IntlProvider
*/
export const snapshotI18n = (component, locale = 'en') => {
const tree = renderer.create(<IntlProvider locale={locale}>{component}</IntlProvider>).toJSON();
return expect(tree).toMatchSnapshot();
};