lmiller1990 / vue-testing-handbook

A guide on testing Vue components and applications
https://lmiller1990.github.io/vue-testing-handbook/
876 stars 160 forks source link

Vue 3 and emitted events #185

Closed bikingbadger closed 3 years ago

bikingbadger commented 3 years ago

With the composition API in Vue 3 and emit not being available in the composition API but should be passed as a parameter I wonder if there should be some mention of it in Testing emitted events.

<template>
  <div></div>
</template>

<script>
export default {
  emits: ['myEvent'],
  setup(props, { emit }) {
    const emitEvent = () => {
      emit('myEvent', 'name', 'password');
    };

    return { emitEvent };
  },
};
</script>

<style></style>

I didn't see this in the Composition chapter and thought that maybe it might need to be mentioned although again the test itself won't really be affected if I understand correctly.

lmiller1990 commented 3 years ago

We could add a small mention that emitted works fine with the Composition API.

We might need to rethink "Testing events without mounting the component". I don't think the call hack is going to work with the Composition API.