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

Assertions on render() wrapped components don't work for elements that aren't an array #192

Open
cableray opened this issue Jul 14, 2017 · 5 comments

Comments

@cableray
Copy link

For example:

const wrapper = render(<span><a href ="foo">first</a><a href ="bar">second</a></span>)
const secondLink = wrapper.find('a')[1]
expect(secondLink).to.have.attr('href', 'bar')

fails (because it expects secondLink to respond to first(), but it isn't an array of results)

This makes it impossible to assert on specific items in an array of results.

@ljharb
Copy link
Member

ljharb commented Jul 14, 2017

[1] doesn't give you a wrapped element. I think you want .at(1).

@cableray
Copy link
Author

Strangely, .at is undefined on wrapper and the result of find('a') 🤔. Is that normal?

Versions:

  • cheerio@0.22.0
  • chai-enzyme@0.7.1

@ljharb
Copy link
Member

ljharb commented Jul 14, 2017

ah, sorry, you're using render. You want .eq(1) then, just like in jquery. Array bracket syntax gets you a raw, unwrapped thing.

@cableray
Copy link
Author

Ok, thanks @ljharb! It is a bummer that this doesn't work with other chai tools like chai-things because of not being a real array, but I'm not sure that would be an easy thing to do.

@ryanblakeley
Copy link

cheerio@v1.0.0-rc.2 is published. Could we have that as an acceptable peer?

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

No branches or pull requests

3 participants