Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Text is not normalized according to testing-library's normalization documentation #391

Open
DanKaplanSES opened this issue Aug 5, 2023 · 0 comments

Comments

@DanKaplanSES
Copy link

Describe the bug
When using testcafe-testing-library, text normalization does not work as documented (emphasis mine):

Normalization

Before running any matching logic against text in the DOM, DOM Testing Library automatically normalizes that text. By default, normalization consists of trimming whitespace from the start and end of text, and collapsing multiple adjacent whitespace characters within the string into a single space.

To Reproduce
Put this content into your html file:

<h1 data-testid="header">
  My Header
</h1>

And put this code into your test file:

import { screen } from '@testing-library/testcafe';
import { Selector } from 'testcafe';
//...
    await t.expect(screen.queryByTestId('header').innerText)
    .eql('My Header')

Expected behavior
This test passes.

Actual behavior
This test fails due to whitespace differences:

   1) AssertionError: expected '\nMy Header\n' to deeply equal 'My Header'

      + expected - actual

      -
      -My Header
      +My Header

Desktop (please complete the following information):

  • OS: Windows 10
  • Browser: Headless Chrome
  • Version: Version 115.0.5790.171 (Official Build) (64-bit)

Additional context
As a workaround, I could manually trim the innerText, but according to the documentation, I shouldn't have to.

Although I haven't tested this, this bug implies that custom normalizers passed into the query functions will be ignored.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

1 participant