How to use the @testing-library/vue.fireEvent.touch function in @testing-library/vue

To help you get started, we’ve selected a few @testing-library/vue examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github testing-library / vue-testing-library / src / __tests__ / validate-plugin.js View on Github external
test('can validate using plugin', async () => {
  // The third argument of `render` is a callback function that receives the
  // Vue instance as a parameter. This way, we can register plugins such as
  // VeeValidate.
  const {getByPlaceholderText, queryByTestId, getByTestId} = render(
    Validate,
    {},
    vue => vue.use(VeeValidate, {events: 'blur'}),
  )

  // Assert error messages are not in the DOM when rendering the component.
  expect(queryByTestId('username-errors')).toBeNull()

  const usernameInput = getByPlaceholderText('Username...')
  await fireEvent.touch(usernameInput)

  // After "touching" the input (focusing and blurring), validation error
  // should appear.
  expect(getByTestId('username-errors')).toHaveTextContent(
    /the username field is required/i,
  )
})