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

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

Closed
pustovalov opened this issue Nov 3, 2020 · 7 comments
Closed

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

pustovalov opened this issue Nov 3, 2020 · 7 comments
Labels
bug Something isn't working

Comments

@pustovalov
Copy link
Contributor

pustovalov commented Nov 3, 2020

  • @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

@marcosvega91
Copy link
Member

Hi @pustovalov thanks for raising this :).

I think that the problem is a regression of my PR #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

@marcosvega91 marcosvega91 added the bug Something isn't working label Nov 3, 2020
@pustovalov
Copy link
Contributor Author

pustovalov commented Nov 3, 2020

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

@marcosvega91
Copy link
Member

I have fixed, sorry for that :)

@marcosvega91
Copy link
Member

marcosvega91 commented Nov 3, 2020

I have close my PR in favor of #804

@marcosvega91
Copy link
Member

@pustovalov let us know if you still have the problem ☺️

@pustovalov
Copy link
Contributor Author

@marcosvega91 can you publish a new version?

@kentcdodds
Copy link
Member

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants