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

attr doesn't work with shallow (only with mount) #205

Open
cuongluu8 opened this issue Oct 18, 2017 · 4 comments
Open

attr doesn't work with shallow (only with mount) #205

cuongluu8 opened this issue Oct 18, 2017 · 4 comments

Comments

@cuongluu8
Copy link

For example

const ReportLink = ({ href }) => (
    <a href={href}>This is a link</a>
);

const props = { href: '/link/to' }
const reportLink = shallow(<ReportLink {...props}/>);
expect(reportLink).to.have.attr('href').equal(props.href);

Gives the following error
Window is not a constructor (evaluating '(0, _cheerio2.default)(this.wrapper.html())')

Works fine if I use mount instead of shallow. Documentation suggests that attr is support in a shallow render.

Using chai-enzyme v0.7.1

@ayrton
Copy link
Contributor

ayrton commented Nov 19, 2017

What happens when you do:

expect(reportLink).to.have.attr('href', props.href);

@ljharb
Copy link
Member

ljharb commented Nov 19, 2017

also what about export(reportLink).to.have.prop('href', props.href)?

@cuongluu8
Copy link
Author

expect(reportLink).to.have.attr('href', props.href); yields the same error.

expect(reportLink).to.have.prop('href', props.href); does work and will probably be sufficient most of the times.

I guess there is an open question on when attr can/should be used? Is it just for full mount rendering?

@ljharb
Copy link
Member

ljharb commented Nov 20, 2017

It’s using full Cheerio rendering; and yes, I’d say shallow rendering assertions are going to consistently be a better bet.

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