2
0
mirror of https://github.com/tenrok/vue-tribute.git synced 2026-06-16 16:50:35 +03:00
Files
vue-tribute/__tests__/VueTributeTest.js
T
Collin Henderson adcd76db33 1.0 release
2018-03-25 14:35:33 -04:00

74 lines
1.9 KiB
JavaScript

import { mount } from 'vue-test-utils'
import VueTribute from '../src'
describe('VueTribute', () => {
let testData = {
options: {
values: [
{ key: 'Phil Heartman', value: 'pheartman' },
{ key: 'Gordon Ramsey', value: 'gramsey' }
]
}
}
it('has a name', () => {
const wrapper = mount(VueTribute, {
slots: {
default: '<input type="text" placeholder="Testo" />'
},
propsData: testData
})
expect(wrapper.name()).toBe('vue-tribute')
})
it('accepts an options prop', () => {
const wrapper = mount(VueTribute, {
slots: {
default: '<input type="text" placeholder="Testo" />'
},
propsData: testData
})
expect(wrapper.props()).toBe(testData)
})
it('fires an event when there are no matches', () => {
const wrapper = mount(VueTribute, {
slots: {
default: '<input type="text" placeholder="Testo" />'
},
propsData: testData
})
const $input = wrapper.find('input[type=text]')
$input.element.value = '@foobar'
const evt = new CustomEvent('tribute-no-match')
$input.element.dispatchEvent(evt)
expect(wrapper.emitted('tribute-no-match')).toBeTruthy()
})
it('fires an event when when the target Tribute element has been updated', () => {
const wrapper = mount(VueTribute, {
slots: {
default: '<input type="text" placeholder="Testo" />'
},
propsData: testData
})
const $input = wrapper.find('input[type=text]')
const evt = new CustomEvent('tribute-replaced')
$input.element.dispatchEvent(evt)
expect(wrapper.emitted('tribute-replaced')).toBeTruthy()
})
function CustomEvent(event, params) {
params = params || { bubbles: false, cancelable: false, detail: undefined }
var evt = document.createEvent('CustomEvent')
evt.initCustomEvent(event, params.bubbles, params.cancelable, params.detail)
return evt
}
})