Skip to content
This repository has been archived by the owner on Feb 7, 2024. It is now read-only.

Commit

Permalink
Fix Emit Decorator with multiple arguments
Browse files Browse the repository at this point in the history
  • Loading branch information
mugi-uno committed Mar 18, 2020
1 parent a5fd1aa commit 9b9fb0e
Show file tree
Hide file tree
Showing 2 changed files with 37 additions and 1 deletion.
2 changes: 1 addition & 1 deletion src/vue-property-decorator.ts
Original file line number Diff line number Diff line change
Expand Up @@ -274,7 +274,7 @@ export function Emit(event?: string) {
} else if (args.length === 1) {
this.$emit(emitName, args[0])
} else {
this.$emit(emitName, args)
this.$emit(emitName, ...args)
}
} else {
this.$emit(emitName, returnValue)
Expand Down
36 changes: 36 additions & 0 deletions tests/Emit.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,42 @@ describe(Emit, () => {
expect(mockFn.mock.calls[0][1]).toBe(value)
})
})

describe('when multiple arguments is given', () => {
@Component
class ChildComponent extends Vue {
count = 0

@Emit() increment(n1: number, n2: number) {
this.count += n1 + n2
}
}

const child = new ChildComponent()
const mockFn = jest.fn()
child.$emit = mockFn

const value1 = 30
const value2 = 40

beforeAll(() => {
child.increment(value1, value2)
})

test('call $emit method', () => {
expect(mockFn).toHaveBeenCalled()
})

test('emit event with method name', () => {
expect(mockFn.mock.calls[0][0]).toBe('increment')
})

test('emit event with multiple arguments', () => {
expect(mockFn.mock.calls[0][1]).toBe(value1)
expect(mockFn.mock.calls[0][2]).toBe(value2)
})
})


describe('when promise has been returned', () => {
const value = 10
Expand Down

0 comments on commit 9b9fb0e

Please sign in to comment.