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

Support testing emitted events #6

Open
asselin opened this issue Mar 1, 2017 · 3 comments
Open

Support testing emitted events #6

asselin opened this issue Mar 1, 2017 · 3 comments

Comments

@asselin
Copy link
Collaborator

asselin commented Mar 1, 2017

@callumacrae FYI, I'm working on an enhancement to allow a unit test to specify event handlers for a component under test so that you can test that a component correctly emits events.

I'm basically trying to get something like this working:

  it('should emit an event', () => {
    var spy = sinon.spy();

    // eslint-disable-next-line no-unused-vars
    const HelloComponent = mount(Hello, {}, '', { someEvent: spy });
    // Do something that should make HelloComponent emit 'someEvent'

    spy.should.have.been.calledOnce;
  });

I hope to have a PR today, but if you have any feedback, I'm happy to hear it.

@callumacrae
Copy link
Owner

That looks really nice! I didn't even think of doing that, because I rarely use events, but this will definitely be useful.

I've invited you to be a collaborator on this repo - thank you for your contributions.

@asselin
Copy link
Collaborator Author

asselin commented Mar 2, 2017

Thanks for adding me as a collaborator!

I just created PR #8 for this feature. It's pretty straightforward, but after posting above, I got to thinking about whether it's a good idea to keep adding parameters to mount().

In PR #7 , I put together an example of an API that takes a hash instead, so usage looks like this:

it('should ...', () => {
    const HelloComponent = mount(Hello, {
      props: {
        prop1: 'foo',
        prop2: 7
      },
      slots: {
        slot1: '<div></div>'
      },
      events: {
        event1: someSpyProbably
      }
    };
  });

PR #7 shouldn't be merged as-is, it's for exploring this option.

Some notes:

What are your thoughts?

@callumacrae
Copy link
Owner

I like the look of that, wonder if it's possible to make it backwards compatible anyway. Let's discuss it on that PR.

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

2 participants