Skip to content

Commit 207ca37

Browse files
Lindsay Gaineslmiller1990
authored andcommitted
test: add emit test for class-style components
1 parent 24ea6f4 commit 207ca37

File tree

1 file changed

+20
-1
lines changed

1 file changed

+20
-1
lines changed

tests/emit.spec.ts

Lines changed: 20 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
import { defineComponent, FunctionalComponent, h, SetupContext } from 'vue'
2+
import { Vue } from 'vue-class-component'
23

34
import { mount } from '../src'
45

@@ -137,7 +138,7 @@ describe('emitted', () => {
137138
expect(wrapper.emitted('hello')).toHaveLength(2)
138139
})
139140

140-
it('gives a useful warning for functional components', () => {
141+
it('captures events emitted by functional components', () => {
141142
const Component: FunctionalComponent<
142143
{ bar: string; level: number },
143144
{ hello: (foo: string, bar: string) => void }
@@ -159,6 +160,24 @@ describe('emitted', () => {
159160
expect(wrapper.emitted('hello')[0]).toEqual(['foo', 'bar'])
160161
})
161162

163+
it('captures events emitted by class-style components', () => {
164+
// Define the component in class-style
165+
class Component extends Vue {
166+
bar = 'bar'
167+
render() {
168+
return h(`h1`, {
169+
onClick: () => this.$emit('hello', 'foo', this.bar)
170+
})
171+
}
172+
}
173+
174+
const wrapper = mount(Component, {})
175+
176+
wrapper.find('h1').trigger('click')
177+
expect(wrapper.emitted('hello')).toHaveLength(1)
178+
expect(wrapper.emitted('hello')[0]).toEqual(['foo', 'bar'])
179+
})
180+
162181
it('captures an event emitted in setup', () => {
163182
const Comp = {
164183
setup(_, { emit }) {

0 commit comments

Comments
 (0)