Skip to content

Instantly share code, notes, and snippets.

@InfoSec812
Last active November 2, 2018 19:38
Show Gist options
  • Select an option

  • Save InfoSec812/13b97edda4b53608fd8e68b8928d05c0 to your computer and use it in GitHub Desktop.

Select an option

Save InfoSec812/13b97edda4b53608fd8e68b8928d05c0 to your computer and use it in GitHub Desktop.
Async Vue Test Utils Example
import { shallowMount } from '@vue/test-utils'
import MessageToggle from '@/components/MessageToggle.vue'
import Message from '@/components/Message'
// Define the test method to be prefixed with `async`
describe('MessageToggle.vue', async () => {
it('toggles msg passed to Message when button is clicked', () => {
const wrapper = shallowMount(MessageToggle)
const button = wrapper.find('#toggle-message')
button.trigger('click')
// Button click triggers an async operation which will not resolve in the current "Tick"
// Await the next "Tick" before making assertions.
await wrapper.nextTick()
const MessageComponent = wrapper.find(Message)
expect(MessageComponent.attributes().msg).toEqual('message')
button.trigger('click')
expect(MessageComponent.attributes().msg).toEqual('toggled message')
})
})
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment