Skip to content

Commit

Permalink
test: catch error
Browse files Browse the repository at this point in the history
  • Loading branch information
zernonia committed May 9, 2024
1 parent af3743b commit 7f03502
Showing 1 changed file with 16 additions and 6 deletions.
22 changes: 16 additions & 6 deletions packages/radix-vue/src/TagsInput/TagsInput.test.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { beforeEach, describe, expect, it } from 'vitest'
import { beforeEach, describe, expect, it, vi } from 'vitest'
import { axe } from 'vitest-axe'
import TagsInput from './story/_TagsInput.vue'
import TagsInputObject from './story/_TagsInputObject.vue'
Expand Down Expand Up @@ -208,7 +208,16 @@ describe('given a TagsInput with objects', async () => {

it('should throw an error if props are not ok', async () => {
document.body.innerHTML = ''
wrapper = mount(TagsInputObject, {
const consoleWarnMockFunction = vi.fn()

const wrapper = mount(TagsInputObject, {
global: {
config: {
errorHandler(err: any) {
consoleWarnMockFunction(err.message)
},
},
},
props: {
displayValue: (item: any) => `Person: ${item.name}`,
convertValue: undefined,
Expand All @@ -217,9 +226,10 @@ describe('given a TagsInput with objects', async () => {
})

input = wrapper.find('input')
expect(() => {
input.setValue('Moriah Stanton')
input.trigger('keydown.enter')
}).toThrow('You must provide a `convertValue` function when using objects as values.')
await input.setValue('Moriah Stanton')
await input.trigger('keydown.enter')

expect(consoleWarnMockFunction).toHaveBeenCalledOnce()
expect(consoleWarnMockFunction).toHaveBeenLastCalledWith('You must provide a `convertValue` function when using objects as values.')
})
})

0 comments on commit 7f03502

Please sign in to comment.