Skip to content

TypeError: Cannot read property 'length' of null (7.26.4) #805

Closed
@pustovalov

Description

@pustovalov
  • @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 (#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

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't working

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions