question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Cannot find HTMLElements by class

See original GitHub issue

Current behavior

It appears that find, can’t find html elements by class like HTMLAnchorElement

Expected behavior

test("can find anchors", ()=> {
  const wrapper = mount(<div><a href="#"></a></div>);

  expect(wrapper.find('a').length).toBe(1); // passes
  expect(wrapper.childAt(0).instance()).toBeInstanceOf(HTMLAnchorElement); //passes
  expect(wrapper.find(HTMLAnchorElement).length).toBe(1); //fails
});

test("can find spans", ()=> {
  const wrapper = mount(<div><span>Test</span></div>);

  expect(wrapper.find('span').length).toBe(1); //passes
  expect(wrapper.childAt(0).instance()).toBeInstanceOf(HTMLSpanElement); //passes
  expect(wrapper.find(HTMLSpanElement).length).toBe(1); //fails
});

Your environment

    "next": "^7.0.2",
    "react": "^16.4.2",
    "react-dom": "^16.4.2",
    "enzyme": "^3.5.0",
    "enzyme-adapter-react-16": "^1.3.0",
    "jest": "^23.5.0",

API

  • shallow
  • mount
  • render

Version

library version
enzyme ^3.5.0
react ^16.4.2
react-dom ^16.4.2
react-test-renderer ???
adapter (below) ^1.3.0

Adapter

  • enzyme-adapter-react-16
  • enzyme-adapter-react-16.3
  • enzyme-adapter-react-16.2
  • enzyme-adapter-react-16.1
  • enzyme-adapter-react-15
  • enzyme-adapter-react-15.4
  • enzyme-adapter-react-14
  • enzyme-adapter-react-13
  • enzyme-adapter-react-helper
  • others ( )

Issue Analytics

  • State:closed
  • Created 5 years ago
  • Comments:14 (12 by maintainers)

github_iconTop GitHub Comments

1reaction
kii-dotcommented, Dec 10, 2018

Ok, got it. I’m gonna write the test cases for all of them and then make a PR for you to check and provide suggestions. When those are good, I’ll work on on the feature then.

1reaction
kii-dotcommented, Dec 7, 2018

I would like to help this out 😃

Read more comments on GitHub >

github_iconTop Results From Across the Web

Cannot detect element by classname - javascript
I am a beginner and I am using pure javascript for DOM manipulation. I am not able to get all the divs in...
Read more >
Cannot find HTMLElements by class · Issue #1929 - GitHub
Current behavior It appears that find, can't find html elements by class like HTMLAnchorElement Expected behavior test("can find anchors", ...
Read more >
Document.getElementsByClassName() - Web APIs | MDN
The getElementsByClassName method of Document interface returns an array-like object of all child elements which have all of the given class ...
Read more >
HTML DOM Element getElementsByClassName() - W3Schools
The getElementsByClassName() method returns a collection of child elements with a given class name. The getElementsByClassName() method returns a NodeList ...
Read more >
How to locate an element on the page - Web Performance
The class attribute: The element has a CSS class (attribute). If this is the first (or only) element on the page using that...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found