-
-
Notifications
You must be signed in to change notification settings - Fork 2k
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
hasClass returns false unexpectedly in v3 #1177
Comments
Your |
you'll actually need to not call
and do |
Thanks for your answers guys. it('toggles calendar on label click', () => {
const component = (
<DatePicker />
);
const mountedComponent = mount(component);
const getDatePicker = () => mountedComponent.find('.DatePicker');
// Opening
getDatePicker().find('.DatePicker__button').simulate('click');
mountedComponent.update();
expect(getDatePicker().hasClass('open')).toBe(true);
// Closing
getDatePicker().find('.DatePicker__button').simulate('click');
mountedComponent.update();
console.log(getDatePicker().getDOMNode().className);
console.log(getDatePicker().hasClass('open'));
expect(getDatePicker().hasClass('open')).toBe(false);
}); ...and here's what the new console.logs are saying: |
hmm. that is strange. Do you think you'd be able to provide a minimal repro in the form of a test or something? |
Sure thing. I'll get back to you! |
Could this be related to #1163? I'm seeing some interesting failures along these lines. If you were to |
I'm having the same issue. And it seems |
I hope I'm on the same page here, but it seems like this isn't even related to dynamic updating of the component. With this test case I get one pass and one fail.
import {mount, shallow} from 'enzyme'
import React from 'react'
const Comp = () => {
return (
<div className="test">
<p>Hello world</p>
</div>
)
}
test('It finds the className on the mount()\'d wrapper', () => {
const mountWrapper = mount(<Comp />)
expect(mountWrapper.hasClass('test')).toBe(true)
})
test('It finds the className on the shallow()\'d wrapper', () => {
const shallowWrapper = shallow(<Comp />)
expect(shallowWrapper.hasClass('test')).toBe(true)
}) npm test -- repro
FAIL ./repro_test.js
● It finds the className on the mount()'d wrapper
expect(received).toBe(expected)
Expected value to be (using ===):
true
Received:
false
at Object.<anonymous> (repro_test.js:14:43)
at Promise (<anonymous>)
at Promise.resolve.then.el (node_modules/p-map/index.js:42:16)
at <anonymous>
at process._tickCallback (internal/process/next_tick.js:188:7)
✕ It finds the className on the mount()'d wrapper (21ms)
✓ It finds the className on the shallow()'d wrapper (4ms) |
@antonyoneill's #1177 (comment) was correct for me; |
The problem seem to be with I didn't notice any issue with |
Also, the v15 adapter and v16 give different results as well. I upgrade to enzyme 3 with v15, then I'm trying to switch to v16, and some of my tests are failing again. All are using |
I have this issue as well:
And this one works:
The only difference is adding find here:
|
@elyobo @antonyoneill mine doesn't even get the class to show up when i do html();
also if i'm using typescript does @types/enzyme take priority over the regular enzyme? |
I'm not exactly sure what is going on here. The fix came from this issue: enzymejs/enzyme#1177
Hi All, any update on this? |
Hi All, Getting the same error for finding the classname and it returns false even though the class exists. Any update on this? |
Also stucked on this bug... This is not working :
=> output
To fix it I had to chain a
Using :
Need a fix to improve this..?! |
I believe this is actually caused by #1153, and that a |
Hi!
I have the following piece of code (simplified), in my Jest/Enzyme based test suite:
I'm getting
false
onhasClass
unexpectedly. The two console.logs I have in the code return as follows:I've tried multiple combinations, like
datePicker.getDOMNode().hasClass
but these are not working either.Thanks in advance for help!
The text was updated successfully, but these errors were encountered: