1
- import { render } from '@testing-library/react' ;
1
+ import { act , render } from '@testing-library/react' ;
2
2
import { createMemoryHistory } from 'history-4' ;
3
3
import * as React from 'react' ;
4
4
import { matchPath , Route , Router , Switch } from 'react-router-4' ;
@@ -125,7 +125,7 @@ describe('React Router v4', () => {
125
125
126
126
it ( 'does not normalize transaction name ' , ( ) => {
127
127
const [ mockStartTransaction , history ] = createInstrumentation ( ) ;
128
- const { container } = render (
128
+ const { getByText } = render (
129
129
< Router history = { history } >
130
130
< Switch >
131
131
< Route path = "/users/:userid" component = { ( ) => < div > UserId</ div > } />
@@ -135,8 +135,10 @@ describe('React Router v4', () => {
135
135
</ Router > ,
136
136
) ;
137
137
138
- history . push ( '/users/123' ) ;
139
- expect ( container . innerHTML ) . toContain ( 'UserId' ) ;
138
+ act ( ( ) => {
139
+ history . push ( '/users/123' ) ;
140
+ } ) ;
141
+ getByText ( 'UserId' ) ;
140
142
141
143
expect ( mockStartTransaction ) . toHaveBeenCalledTimes ( 2 ) ;
142
144
expect ( mockStartTransaction ) . toHaveBeenLastCalledWith ( {
@@ -149,7 +151,7 @@ describe('React Router v4', () => {
149
151
it ( 'normalizes transaction name with custom Route' , ( ) => {
150
152
const [ mockStartTransaction , history , { mockSetName } ] = createInstrumentation ( ) ;
151
153
const SentryRoute = withSentryRouting ( Route ) ;
152
- const { container } = render (
154
+ const { getByText } = render (
153
155
< Router history = { history } >
154
156
< Switch >
155
157
< SentryRoute path = "/users/:userid" component = { ( ) => < div > UserId</ div > } />
@@ -159,8 +161,10 @@ describe('React Router v4', () => {
159
161
</ Router > ,
160
162
) ;
161
163
162
- history . push ( '/users/123' ) ;
163
- expect ( container . innerHTML ) . toContain ( 'UserId' ) ;
164
+ act ( ( ) => {
165
+ history . push ( '/users/123' ) ;
166
+ } ) ;
167
+ getByText ( 'UserId' ) ;
164
168
165
169
expect ( mockStartTransaction ) . toHaveBeenCalledTimes ( 2 ) ;
166
170
expect ( mockStartTransaction ) . toHaveBeenLastCalledWith ( {
@@ -175,7 +179,7 @@ describe('React Router v4', () => {
175
179
it ( 'normalizes nested transaction names with custom Route' , ( ) => {
176
180
const [ mockStartTransaction , history , { mockSetName } ] = createInstrumentation ( ) ;
177
181
const SentryRoute = withSentryRouting ( Route ) ;
178
- const { container } = render (
182
+ const { getByText } = render (
179
183
< Router history = { history } >
180
184
< Switch >
181
185
< SentryRoute path = "/organizations/:orgid/v1/:teamid" component = { ( ) => < div > Team</ div > } />
@@ -185,8 +189,10 @@ describe('React Router v4', () => {
185
189
</ Router > ,
186
190
) ;
187
191
188
- history . push ( '/organizations/1234/v1/758' ) ;
189
- expect ( container . innerHTML ) . toContain ( 'Team' ) ;
192
+ act ( ( ) => {
193
+ history . push ( '/organizations/1234/v1/758' ) ;
194
+ } ) ;
195
+ getByText ( 'Team' ) ;
190
196
191
197
expect ( mockStartTransaction ) . toHaveBeenCalledTimes ( 2 ) ;
192
198
expect ( mockStartTransaction ) . toHaveBeenLastCalledWith ( {
@@ -197,8 +203,10 @@ describe('React Router v4', () => {
197
203
expect ( mockSetName ) . toHaveBeenCalledTimes ( 2 ) ;
198
204
expect ( mockSetName ) . toHaveBeenLastCalledWith ( '/organizations/:orgid/v1/:teamid' ) ;
199
205
200
- history . push ( '/organizations/543' ) ;
201
- expect ( container . innerHTML ) . toContain ( 'OrgId' ) ;
206
+ act ( ( ) => {
207
+ history . push ( '/organizations/543' ) ;
208
+ } ) ;
209
+ getByText ( 'OrgId' ) ;
202
210
203
211
expect ( mockStartTransaction ) . toHaveBeenCalledTimes ( 3 ) ;
204
212
expect ( mockStartTransaction ) . toHaveBeenLastCalledWith ( {
0 commit comments