Dom-testing-library: TypeError: Cannot read property 'length' of null (7.26.4)

Created on 3 Nov 2020  路  7Comments  路  Source: testing-library/dom-testing-library

  • @testing-library/dom version: 7.26.4
  • Testing Framework and version:

    jest: 26.6.2
  • DOM Environment:

    jsdom: 8.5.0

Relevant code or config:

  test(`should select rule type from selector`, async () => {
    renderCampaignShowRoot({
      store: rootStore,
      activeRoute,
    })

    const createRuleButton = await screen.findByTestId(
      'ac-cr-loyalty-create-new-rule',
    )

    userEvent.click(createRuleButton)
    expect(
      await screen.findByTestId('ac-cr-loyalty-create-rule-modal'),
    ).toBeInTheDocument()

    const select = screen.getByLabelText('Action type')

    await selectEvent.select(select, 'Purchase points')

    expect(await screen.findByText('Purchase points')).toBeInTheDocument()
  })

What happened:

    TypeError: Cannot read property 'length' of null

      314 |           ).toBeInTheDocument()
      315 |
    > 316 |           const select = screen.getByLabelText('Action type')
          |                                 ^
      317 |
      318 |           await selectEvent.select(select, 'Purchase points')
      319 |

      at node_modules/@testing-library/dom/dist/queries/label-text.js:63:53
          at Array.filter (<anonymous>)
      at queryAllByLabelText (node_modules/@testing-library/dom/dist/queries/label-text.js:62:80)
      at getAllByLabelText (node_modules/@testing-library/dom/dist/queries/label-text.js:101:15)
      at node_modules/@testing-library/dom/dist/query-helpers.js:62:17
      at getByLabelText (node_modules/@testing-library/dom/dist/query-helpers.js:106:19)

Problem description:


After update @testing-library/dom: 7.26.3 -> 7.26.4 (https://github.com/testing-library/dom-testing-library/pull/790), tests started to fall

These changes affected specs which use these helpers:

findByLabelText
getByLabelText

other specs works fine

Suggested solution:

Add to docs what users should do to fix this or fix this behavior

bug

Most helpful comment

New versions are released automatically. Unfortunately TravisCI recently made changes to their OSS plan which severely limits how frequently those runs happen. I'm investigating moving to GitHub actions for this. But you'll get a new version soon (most likely in the next few hours). Thanks for your patience.

All 7 comments

Hi @pustovalov thanks for raising this :).

I think that the problem is a regression of my PR https://github.com/testing-library/dom-testing-library/pull/790

I didn't know that if an input is hidden the labels attribute is null and not an empty NodeList.
https://html.spec.whatwg.org/multipage/forms.html#dom-lfe-labels

At first didn't find your PR in releases, looks like refactor PR's not counted for release

https://github.com/testing-library/dom-testing-library/releases

I have fixed, sorry for that :)

I have close my PR in favor of #804

@pustovalov let us know if you still have the problem 鈽猴笍

@marcosvega91 can you publish a new version?

New versions are released automatically. Unfortunately TravisCI recently made changes to their OSS plan which severely limits how frequently those runs happen. I'm investigating moving to GitHub actions for this. But you'll get a new version soon (most likely in the next few hours). Thanks for your patience.

Was this page helpful?
0 / 5 - 0 ratings