Skip to content

With event does not override currentTarget #69

Description

@salomvary

I expected this to pass:

        it('calls events with currentTarget', () => {

            const EventTargetComponent = () => {
                const [value, setValue] = useState();
                const handleChange = (event) => setValue(event.currentTarget.value);
                return <div><input onChange={handleChange} value="before-change"/><span>{value}</span></div>;
            }

            expect(<EventTargetComponent/>, 'when deeply rendered', 'with event',
                  'change', { currentTarget: {value: 'test'} }, 'on', <input/>, 'to have rendered',
                <div>
                    <input/>
                    <span>test</span>
                </div>);
        });

But it failed with this:

  2) unexpected-react (deep rendering) with events calls events with currentTarget:
     UnexpectedError: 
expected <EventTargetComponent />
when deeply rendered with event 'change', { currentTarget: { value: 'test' } } on <input /> to have rendered <div><input /><span>test</span></div>

<EventTargetComponent>
  <div>
    <input onChange={function handleChange(event) { /* ... */ }} value="before-change" />
    <span>
      before-change // before-change
                    // test
    </span>
  </div>

Does this maybe mean the deep renderer does not allow triggering events with arbitrary properties? The documentation suggests that it should be possible..

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions