Skip to content

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

@DanKaplanSES

Description

@DanKaplanSES

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.

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions