1- import { render } from '@testing-library/react' ;
1+ import { act , render } from '@testing-library/react' ;
22import { createMemoryHistory } from 'history-4' ;
33import * as React from 'react' ;
44import { matchPath , Route , Router , Switch } from 'react-router-4' ;
@@ -125,7 +125,7 @@ describe('React Router v4', () => {
125125
126126 it ( 'does not normalize transaction name ' , ( ) => {
127127 const [ mockStartTransaction , history ] = createInstrumentation ( ) ;
128- const { container } = render (
128+ const { getByText } = render (
129129 < Router history = { history } >
130130 < Switch >
131131 < Route path = "/users/:userid" component = { ( ) => < div > UserId</ div > } />
@@ -135,8 +135,10 @@ describe('React Router v4', () => {
135135 </ Router > ,
136136 ) ;
137137
138- history . push ( '/users/123' ) ;
139- expect ( container . innerHTML ) . toContain ( 'UserId' ) ;
138+ act ( ( ) => {
139+ history . push ( '/users/123' ) ;
140+ } ) ;
141+ getByText ( 'UserId' ) ;
140142
141143 expect ( mockStartTransaction ) . toHaveBeenCalledTimes ( 2 ) ;
142144 expect ( mockStartTransaction ) . toHaveBeenLastCalledWith ( {
@@ -149,7 +151,7 @@ describe('React Router v4', () => {
149151 it ( 'normalizes transaction name with custom Route' , ( ) => {
150152 const [ mockStartTransaction , history , { mockSetName } ] = createInstrumentation ( ) ;
151153 const SentryRoute = withSentryRouting ( Route ) ;
152- const { container } = render (
154+ const { getByText } = render (
153155 < Router history = { history } >
154156 < Switch >
155157 < SentryRoute path = "/users/:userid" component = { ( ) => < div > UserId</ div > } />
@@ -159,8 +161,10 @@ describe('React Router v4', () => {
159161 </ Router > ,
160162 ) ;
161163
162- history . push ( '/users/123' ) ;
163- expect ( container . innerHTML ) . toContain ( 'UserId' ) ;
164+ act ( ( ) => {
165+ history . push ( '/users/123' ) ;
166+ } ) ;
167+ getByText ( 'UserId' ) ;
164168
165169 expect ( mockStartTransaction ) . toHaveBeenCalledTimes ( 2 ) ;
166170 expect ( mockStartTransaction ) . toHaveBeenLastCalledWith ( {
@@ -175,7 +179,7 @@ describe('React Router v4', () => {
175179 it ( 'normalizes nested transaction names with custom Route' , ( ) => {
176180 const [ mockStartTransaction , history , { mockSetName } ] = createInstrumentation ( ) ;
177181 const SentryRoute = withSentryRouting ( Route ) ;
178- const { container } = render (
182+ const { getByText } = render (
179183 < Router history = { history } >
180184 < Switch >
181185 < SentryRoute path = "/organizations/:orgid/v1/:teamid" component = { ( ) => < div > Team</ div > } />
@@ -185,8 +189,10 @@ describe('React Router v4', () => {
185189 </ Router > ,
186190 ) ;
187191
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' ) ;
190196
191197 expect ( mockStartTransaction ) . toHaveBeenCalledTimes ( 2 ) ;
192198 expect ( mockStartTransaction ) . toHaveBeenLastCalledWith ( {
@@ -197,8 +203,10 @@ describe('React Router v4', () => {
197203 expect ( mockSetName ) . toHaveBeenCalledTimes ( 2 ) ;
198204 expect ( mockSetName ) . toHaveBeenLastCalledWith ( '/organizations/:orgid/v1/:teamid' ) ;
199205
200- history . push ( '/organizations/543' ) ;
201- expect ( container . innerHTML ) . toContain ( 'OrgId' ) ;
206+ act ( ( ) => {
207+ history . push ( '/organizations/543' ) ;
208+ } ) ;
209+ getByText ( 'OrgId' ) ;
202210
203211 expect ( mockStartTransaction ) . toHaveBeenCalledTimes ( 3 ) ;
204212 expect ( mockStartTransaction ) . toHaveBeenLastCalledWith ( {
0 commit comments