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

Simulate does not merge arguments correctly #1114

Open
danrot opened this issue Sep 15, 2017 · 6 comments
Open

Simulate does not merge arguments correctly #1114

danrot opened this issue Sep 15, 2017 · 6 comments

Comments

@danrot
Copy link

danrot commented Sep 15, 2017

I am using enzyme 2.9.1 (and jest, if this might be somehow connected to the issue), and I am trying to test something that involves a checkbox. But IMO the second parameter of the simulate method doesn't work correctly... I have narrowed it down to the following code:

const test = mount(<input type="checkbox" onChange={(e) => console.log(e.currentTarget.checked)} />);
test.find('input').simulate('change', {currentTarget: {checked: true}});

The console.log here should print true IMO, but it actually prints false. It feels like the second parameter of the simulate call are merged in the wrong way, because the following prints true as I would expect:

const test = mount(<input type="checkbox" onChange={(e) => console.log(e.checked)} />);
test.find('input').simulate('change', {checked: true});

Am I doing something wrong, or is that really a bug?

@danrot
Copy link
Author

danrot commented Sep 27, 2017

@lelandrichardson Has this issue be resolved? Or have I misused it? Just closing it without any information is a bit harsh...

@lelandrichardson
Copy link
Collaborator

oh my gosh, sorry @danrot. I was cycling through issues really quick last night and i think i mixed this issue up as being fixed by #1088 but i think they're different things. I saw the "Merged" issue above and assumed that it was a merged fix. Sorry about that.

@lelandrichardson
Copy link
Collaborator

if you change the first level property from currentTarget to something like foo, is e.foo.checked true?

@danrot
Copy link
Author

danrot commented Sep 27, 2017

Do you mean like this?

const test = mount(<input type="checkbox" onChange={(e) => console.log(e.foo.checked)} />);
test.find('input').simulate('change', {foo: {checked: true}});

This is returning true, yes.

@zachrip
Copy link

zachrip commented Oct 4, 2017

I have also confirmed that @lelandrichardson @danrot, sounds like the merge is backwards.

Edit: the merge looks fine in react-dom/test-utils...
Edit: it actually looks like it's this issue: #218

@Fabianopb
Copy link

Fabianopb commented May 30, 2018

Not sure if this is related to this issue, but multiple arguments doesn't seem to behave as expected either (it works with shallow, though)

const wrapper = mount(<div onChange={(e, data) => console.log("data:", data)}>content</div>);
wrapper.find("div").simulate("change", {}, "some data");
// it will log "data: undefined" instead of "data: some data"

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

4 participants