Last active
May 31, 2021 13:18
-
-
Save aptiko/533357d339baa46cd88644aa2247a036 to your computer and use it in GitHub Desktop.
How to test custom Vue events
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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