Examples · Testing Library

PHOTO EMBED

Mon Oct 19 2020 08:02:18 GMT+0000 (Coordinated Universal Time)

Saved by @sharmanilay #vue.js

import { render, fireEvent } from '@testing-library/vue'
import Component from './Component.vue'

test('properly handles v-model', async () => {
  const { getByLabelText, getByText } = render(Component)

  // Asserts initial state.
  getByText('Hi, my name is Alice')

  // Get the input DOM node by querying the associated label.
  const usernameInput = getByLabelText(/username/i)

  // Updates the <input> value and triggers an `input` event.
  // fireEvent.input() would make the test fail.
  await fireEvent.update(usernameInput, 'Bob')

  getByText('Hi, my name is Bob')
})
content_copyCOPY

https://testing-library.com/docs/vue-testing-library/examples