|
@@ -2,6 +2,8 @@ import {cache} from '@emotion/css'; // eslint-disable-line emotion/no-vanilla
|
|
import {CacheProvider, ThemeProvider} from '@emotion/react';
|
|
import {CacheProvider, ThemeProvider} from '@emotion/react';
|
|
import {mount, shallow as enzymeShallow} from 'enzyme'; // eslint-disable-line no-restricted-imports
|
|
import {mount, shallow as enzymeShallow} from 'enzyme'; // eslint-disable-line no-restricted-imports
|
|
|
|
|
|
|
|
+import {act} from 'sentry-test/reactTestingLibrary';
|
|
|
|
+
|
|
import {lightTheme} from 'app/utils/theme';
|
|
import {lightTheme} from 'app/utils/theme';
|
|
|
|
|
|
/**
|
|
/**
|
|
@@ -9,7 +11,7 @@ import {lightTheme} from 'app/utils/theme';
|
|
* As we are migrating our tests to React Testing Library,
|
|
* As we are migrating our tests to React Testing Library,
|
|
* please avoid using `sentry-test/enzyme/mountWithTheme` and use `sentry-test/reactTestingLibrary/mountWithTheme` instead.
|
|
* please avoid using `sentry-test/enzyme/mountWithTheme` and use `sentry-test/reactTestingLibrary/mountWithTheme` instead.
|
|
*/
|
|
*/
|
|
-const mountWithTheme = (tree, opts) => {
|
|
|
|
|
|
+export function mountWithTheme(tree, opts) {
|
|
const WrappingThemeProvider = props => (
|
|
const WrappingThemeProvider = props => (
|
|
<CacheProvider value={cache}>
|
|
<CacheProvider value={cache}>
|
|
<ThemeProvider theme={lightTheme}>{props.children}</ThemeProvider>
|
|
<ThemeProvider theme={lightTheme}>{props.children}</ThemeProvider>
|
|
@@ -17,13 +19,32 @@ const mountWithTheme = (tree, opts) => {
|
|
);
|
|
);
|
|
|
|
|
|
return mount(tree, {wrappingComponent: WrappingThemeProvider, ...opts});
|
|
return mount(tree, {wrappingComponent: WrappingThemeProvider, ...opts});
|
|
-};
|
|
|
|
|
|
+}
|
|
|
|
|
|
/**
|
|
/**
|
|
* @deprecated
|
|
* @deprecated
|
|
* As we are migrating our tests to React Testing Library,
|
|
* As we are migrating our tests to React Testing Library,
|
|
* please avoid using `sentry-test/enzyme/shallow` and use `sentry-test/reactTestingLibrary/mountWithTheme` instead.
|
|
* please avoid using `sentry-test/enzyme/shallow` and use `sentry-test/reactTestingLibrary/mountWithTheme` instead.
|
|
*/
|
|
*/
|
|
-const shallow = enzymeShallow;
|
|
|
|
|
|
+export const shallow = enzymeShallow;
|
|
|
|
+
|
|
|
|
+/**
|
|
|
|
+ * Force the useLegacyStore setState updates to be wrapped in act.
|
|
|
|
+ *
|
|
|
|
+ * This is useful for old-style enzyme tests where enzyme does not correctly
|
|
|
|
+ * wrap things in `act()` for you.
|
|
|
|
+ *
|
|
|
|
+ * Do NOT use this in RTL tests, as setState's triggered by store updates
|
|
|
|
+ * should be captured with RTL style tests.
|
|
|
|
+ */
|
|
|
|
+export function enforceActOnUseLegacyStoreHook() {
|
|
|
|
+ const originalHook = window._legacyStoreHookUpdate;
|
|
|
|
+
|
|
|
|
+ beforeEach(() => {
|
|
|
|
+ window._legacyStoreHookUpdate = update => act(update);
|
|
|
|
+ });
|
|
|
|
|
|
-export {mountWithTheme, shallow};
|
|
|
|
|
|
+ afterEach(() => {
|
|
|
|
+ window._legacyStoreHookUpdate = originalHook;
|
|
|
|
+ });
|
|
|
|
+}
|