Skip to content

Commit c24c55d

Browse files
authored
test(js): Provide a default legacy context in RTL render (#44801)
There are unfortunately multiple consumers of legacy context still in the app, such as `withOrganization` and react-router. Tests are sometimes broken without passing in `context` to the RTL `render` function because of this, which can be incredibly confusing. For example, `Link`s render without an href. This change simply provides a default so tests are simpler to write.
1 parent abdfcfd commit c24c55d

File tree

2 files changed

+9
-5
lines changed

2 files changed

+9
-5
lines changed

static/app/views/onboarding/createSampleEventButton.spec.jsx

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,8 @@ describe('CreateSampleEventButton', function () {
2222
project={{...project, platform: 'javascript'}}
2323
>
2424
{createSampleText}
25-
</CreateSampleEventButton>
25+
</CreateSampleEventButton>,
26+
{organization: org}
2627
);
2728
}
2829

tests/js/sentry-test/reactTestingLibrary.tsx

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import {Component, Fragment} from 'react';
1+
import {Component} from 'react';
22
import {InjectedRouter} from 'react-router';
33
import {cache} from '@emotion/css'; // eslint-disable-line @emotion/no-vanilla
44
import {CacheProvider, ThemeProvider} from '@emotion/react';
@@ -44,9 +44,12 @@ function createProvider(contextDefs: Record<string, any>) {
4444
}
4545

4646
function makeAllTheProviders({context, ...initializeOrgOptions}: ProviderOptions) {
47-
const ContextProvider = context ? createProvider(context) : Fragment;
48-
49-
const {organization, router} = initializeOrg(initializeOrgOptions as any);
47+
const {organization, router, routerContext} = initializeOrg(
48+
initializeOrgOptions as any
49+
);
50+
const ContextProvider = context
51+
? createProvider(context)
52+
: createProvider(routerContext);
5053

5154
return function ({children}: {children?: React.ReactNode}) {
5255
return (

0 commit comments

Comments
 (0)