enzymejs / enzyme-matchers

Jasmine/Jest assertions for enzyme
MIT License
892 stars 116 forks source link

toBeDisabled not working as expected #332

Closed Blacktiger closed 4 years ago

Blacktiger commented 4 years ago

Not sure why this is happening, but the button is definitely not disabled.

Expected node (Button) not to be "disabled" but it was
Node HTML output: <button class="button button-primary" type="submit">Save</button>

  91 |     simulateChange(wrapper.find('select[name="defaultRole"]'), 'anonymous');
  92 |
> 93 |     expect(saveButton).not.toBeDisabled();
Blacktiger commented 4 years ago

Doing some jest debugging, even though the disabled attribute is not on the html, if I ask for .prop('disabled') I get a true value.

blainekasten commented 4 years ago

I would need to see more code to be able to help. At it's simplest form, toBeDisabled is just a wrapper around .prop('disabled') see, https://github.com/FormidableLabs/enzyme-matchers/blob/master/packages/enzyme-matchers/src/assertions/toBeDisabled.js#L15

So if you have are getting true with the direct prop() call, it must be an issue with your code. I'm going to close this issue because i'm 100% confident there is no bug in this library related to this. But happy to dive into this if you provide more code

ljharb commented 4 years ago

@Blacktiger this is likely that you're misusing enzyme; specifically, you can't reuse found wrappers. You have to re-find from the root every time.

Blacktiger commented 4 years ago

Ah, that's probably what's wrong. Thanks @ljharb!