Cannot find HTMLElements by class
See original GitHub issueCurrent 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:
- Created 5 years ago
- Comments:14 (12 by maintainers)
Top 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 >
Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free
Top Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
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.
I would like to help this out 😃