Skip to content

Instantly share code, notes, and snippets.

@aptiko
Last active May 31, 2021 13:18
Show Gist options
  • Save aptiko/533357d339baa46cd88644aa2247a036 to your computer and use it in GitHub Desktop.
Save aptiko/533357d339baa46cd88644aa2247a036 to your computer and use it in GitHub Desktop.
How to test custom Vue events
import { shallowMount } from '@vue/test-utils'
import LoginForm from '@/components/LoginForm.vue'
import { BootstrapVue, BModal } from 'bootstrap-vue'
describe('LoginForm', () => {
let wrapper
beforeAll(() => {
Vue.use(BootstrapVue)
const container = document.createElement('div')
document.body.appendChild(container)
wrapper = shallowMount(LoginForm, { attachTo: container })
})
test('focuses on username upon showing', () => {
const modal = wrapper.findComponent(BModal)
wrapper.vm.$refs.username = { $el: { focus: jest.fn() } }
modal.vm.$emit('shown')
expect(wrapper.vm.$refs.username.$el.focus).toHaveBeenCalled()
})
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment