Skip to content

Commit

Permalink
chore: improve test
Browse files Browse the repository at this point in the history
  • Loading branch information
devcorpio committed Aug 8, 2023
1 parent 2bcd939 commit c6f80ab
Showing 1 changed file with 19 additions and 5 deletions.
24 changes: 19 additions & 5 deletions packages/rum-react/test/specs/get-apm-routes.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -252,6 +252,21 @@ describe('ApmRoutes', function () {
)
}

function ComponentWithChild() {
navigate = useNavigate()
const [searchParams] = useSearchParams()

if (searchParams.toString() === 'test=elastic') {
return <div>hello Elastic</div>
}

return (
<div>
<Child params={searchParams.toString()} />
</div>
)
}

function Child(props) {
return <h1>Query params: {props.params}</h1>
}
Expand Down Expand Up @@ -280,17 +295,16 @@ describe('ApmRoutes', function () {
}
)

var childComponent = rendered.find(Child)
expect(childComponent.text()).toBe('Query params: ')
var component = rendered.find(ComponentWithChild)
expect(component.text()).toBe('Query params: ')

transactionService.startTransaction.calls.reset()

// Update query param
navigate('?test=elastic')

expect(transactionService.startTransaction).not.toHaveBeenCalled()

// Confirm the child component content is different than before
expect(childComponent.text()).toBe('Query params: test=elastic')
// Confirm the component content is different than before
expect(component.text()).toBe('hello Elastic')
})
})

0 comments on commit c6f80ab

Please sign in to comment.