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

id selector does not seem to work #64

Closed
clouddra opened this issue Dec 10, 2015 · 5 comments
Closed

id selector does not seem to work #64

clouddra opened this issue Dec 10, 2015 · 5 comments
Labels

Comments

@clouddra
Copy link

Was trying to test a simple piece of code:

const renderShallow = shallow(<div id='ttt' className='ttt'>hello</div>);
console.log(renderShallow.find('#ttt')); // not found
console.log(renderShallow.find('.ttt')); // found

and it returns an empty array when i tried to use an id selector. It works fine on class selectors.

@clouddra
Copy link
Author

Just to add, I had the following configuration in my karma config. Not sure if it affects for shallow rendering.

externals: {
        'jsdom': 'window',
        'cheerio': 'window',
        'react/lib/ExecutionEnvironment': true,
}

@lelandrichardson
Copy link
Collaborator

Hi @clouddra, can you confirm that the following code works?

const wrapper = shallow(
  <div>
    <div id='ttt' className='ttt'>hello</div>
  </div>
);
console.log(wrapper.find('#ttt').length); // 1

There may be some edge-case behavior when the id you are looking for is on the root node... especially if you're using React 0.14, where shallow rendering of a DOM Element as opposed to a composite component is behavior shimmed by enzyme rather than built in to the shallow renderer.

@lelandrichardson
Copy link
Collaborator

Confirmed the issue and fixed. Will publish to npm later today when this lands.

@lelandrichardson
Copy link
Collaborator

@clouddra The fix is now available in v1.2.0

@clouddra
Copy link
Author

@lelandrichardson That was fast! Tested it and it works fine. Thanks a lot for your help.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

2 participants