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

feat(simulate): support promise event on simulate #867

Closed
wants to merge 1 commit into from
Closed

feat(simulate): support promise event on simulate #867

wants to merge 1 commit into from

Conversation

yutin1987
Copy link

#823 simulate events returning promises

@yutin1987
Copy link
Author

2017-04-02 12 40 52

@nfcampos
Copy link
Collaborator

nfcampos commented Apr 1, 2017

I don't think I agree with this. Always returning a promise from simulate seems to suggest the event system is somehow asynchronous (which it itsn't) and users of the library should always wait for the promise to resolve before proceeding with their tests.

For the use case you exemplify in the test you added, why not do this?

    it('should simulate promise events', (done) => {
      class Foo extends React.Component {
        ...
      }

      const wrapper = shallow(<Foo />);

      expect(wrapper.find('.clicks-0').length).to.equal(1);
      wrapper.prop('onClick')().then(() => {
        expect(wrapper.find('.clicks-1').length).to.equal(1);
        done();
      });
    });

ie. select the value of the onClick prop and call it directly

@ljharb
Copy link
Member

ljharb commented Apr 1, 2017

Events are not appropriate to model as Promises. Events happen multiple times; a promise resolves once.

Also, yes, events are synchronous in the browser.

You can wrap yourself with new Promise to avoid the done pattern.

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

Successfully merging this pull request may close these issues.

None yet

3 participants