Jest query (get, query, find) has some powerful normalization setting, and when not aware of them could cause trouble:
https://testing-library.com/docs/queries/about/#normalization

1
2
3
4
// component
<<h2 className="vd-align-center">
`Tap, insert, or swipe the customer's card\n used in the original sale.`
</h2>
1
2
3
4
5
6
7
8
9
10
11
// will not pass because collapseWhitespace defaults to true \n is collapsed into a single space
expect(screen.getByText(`Tap, insert, or swipe the customer's card\nused in the original sale.`)).toBeVisible()

// will pass by querying the collapsed text
expect(screen.getByText(`Tap, insert, or swipe the customer's card used in the original sale.`)).toBeVisible()

// will pass by disabling collapseWhitespace
expect(screen.getByText(`Tap, insert, or swipe the customer's card\nused in the original sale.`{
normalizer: getDefaultNormalizer({ collapseWhitespace: false }),
}))
.toBeVisible()