Skip to content

Commit bd89da7

Browse files
committed
test: nested case
1 parent da4e2b3 commit bd89da7

File tree

1 file changed

+39
-24
lines changed

1 file changed

+39
-24
lines changed

packages/react/test/reactrouterv3.test.tsx

Lines changed: 39 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -9,37 +9,26 @@ declare module 'react-router-3' {
99
type History = { replace: Function; push: Function };
1010
export function createMemoryHistory(): History;
1111
export const Router: React.ComponentType<{ history: History }>;
12-
export const Route: React.ComponentType<{ path: string; component: React.ComponentType<any> }>;
12+
export const Route: React.ComponentType<{ path: string; component?: React.ComponentType<any> }>;
1313
export const IndexRoute: React.ComponentType<{ component: React.ComponentType<any> }>;
1414
export const match: Match;
1515
export const createRoutes: (routes: any) => RouteType[];
1616
}
1717

18-
const App: React.FC = ({ children }) => <div>{children}</div>;
19-
20-
function Home(): JSX.Element {
21-
return <div>Home</div>;
22-
}
23-
24-
function About(): JSX.Element {
25-
return <div>About</div>;
26-
}
27-
28-
function Features(): JSX.Element {
29-
return <div>Features</div>;
30-
}
31-
32-
function Users({ params }: { params: Record<string, string> }): JSX.Element {
33-
return <div>{params.userid}</div>;
34-
}
35-
3618
describe('React Router V3', () => {
3719
const routes = (
38-
<Route path="/" component={App}>
39-
<IndexRoute component={Home} />
40-
<Route path="about" component={About} />
41-
<Route path="features" component={Features} />
42-
<Route path="users/:userid" component={Users} />
20+
<Route path="/" component={({ children }: { children: JSX.Element }) => <div>{children}</div>}>
21+
<IndexRoute component={() => <div>Home</div>} />
22+
<Route path="about" component={() => <div>About</div>} />
23+
<Route path="features" component={() => <div>Features</div>} />
24+
<Route
25+
path="users/:userid"
26+
component={({ params }: { params: Record<string, string> }) => <div>{params.userid}</div>}
27+
/>
28+
<Route path="organizations/">
29+
<Route path=":orgid" component={() => <div>OrgId</div>} />
30+
<Route path=":orgid/v1/:teamid" component={() => <div>Team</div>} />
31+
</Route>
4332
</Route>
4433
);
4534
const history = createMemoryHistory();
@@ -129,4 +118,30 @@ describe('React Router V3', () => {
129118
tags: { from: '/', 'routing.instrumentation': 'react-router-v3' },
130119
});
131120
});
121+
122+
it('normalizes nested transaction names', () => {
123+
const mockStartTransaction = jest.fn();
124+
instrumentation(mockStartTransaction);
125+
const { container } = render(<Router history={history}>{routes}</Router>);
126+
127+
history.push('/organizations/1234/v1/758');
128+
expect(container.innerHTML).toContain('Team');
129+
130+
expect(mockStartTransaction).toHaveBeenCalledTimes(2);
131+
expect(mockStartTransaction).toHaveBeenLastCalledWith({
132+
name: '/organizations/:orgid/v1/:teamid',
133+
op: 'navigation',
134+
tags: { from: '/', 'routing.instrumentation': 'react-router-v3' },
135+
});
136+
137+
history.push('/organizations/543');
138+
expect(container.innerHTML).toContain('OrgId');
139+
140+
expect(mockStartTransaction).toHaveBeenCalledTimes(3);
141+
expect(mockStartTransaction).toHaveBeenLastCalledWith({
142+
name: '/organizations/:orgid',
143+
op: 'navigation',
144+
tags: { from: '/organizations/:orgid/v1/:teamid', 'routing.instrumentation': 'react-router-v3' },
145+
});
146+
});
132147
});

0 commit comments

Comments
 (0)