How to use the @testing-library/vue.fireEvent.update 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__ / select.js View on Github external
test('Select component', async () => {
  let optionElement
  const {getByDisplayValue, getByText} = render(Select)

  // Get the Select element by using the initially displayed value.
  const select = getByDisplayValue('Tyrannosaurus')
  expect(select.value).toBe('dino1')

  // Update it by manually sending a valid option value.
  await fireEvent.update(select, 'dino2')
  expect(select.value).toBe('dino2')

  // We can trigger an update event by directly getting the <option> element.
  optionElement = getByText('Deinonychus')
  await fireEvent.update(optionElement)
  expect(select.value).toBe('dino3')

  // ...even if option is within an </option><optgroup>.
  optionElement = getByText('Diplodocus')
  await fireEvent.update(optionElement)
  expect(select.value).toBe('dino4')
})
</optgroup>
github testing-library / vue-testing-library / src / __tests__ / select.js View on Github external
test('Select component', async () =&gt; {
  let optionElement
  const {getByDisplayValue, getByText} = render(Select)

  // Get the Select element by using the initially displayed value.
  const select = getByDisplayValue('Tyrannosaurus')
  expect(select.value).toBe('dino1')

  // Update it by manually sending a valid option value.
  await fireEvent.update(select, 'dino2')
  expect(select.value).toBe('dino2')

  // We can trigger an update event by directly getting the <option> element.
  optionElement = getByText('Deinonychus')
  await fireEvent.update(optionElement)
  expect(select.value).toBe('dino3')

  // ...even if option is within an </option><optgroup>.
  optionElement = getByText('Diplodocus')
  await fireEvent.update(optionElement)
  expect(select.value).toBe('dino4')
})
</optgroup>
github testing-library / vue-testing-library / src / __tests__ / form.js View on Github external
getByText,
    getByRole,
    getByPlaceholderText,
    emitted,
  } = render(Form)

  const submitButton = getByText('Submit')

  // Initially the submit button should be disabled.
  expect(submitButton).toBeDisabled()

  const titleInput = getByLabelText(/title of the movie/i)
  await fireEvent.update(titleInput, fakeReview.title)

  const reviewTextarea = getByPlaceholderText('Write an awesome review')
  await fireEvent.update(reviewTextarea, fakeReview.review)

  // Rating Radio buttons.
  const initiallySelectedInput = getByLabelText('Awful')
  const ratingSelect = getByLabelText('Wonderful')

  expect(initiallySelectedInput.checked).toBe(true)
  expect(ratingSelect.checked).toBe(false)

  await fireEvent.update(ratingSelect)

  expect(ratingSelect.checked).toBe(true)
  expect(initiallySelectedInput.checked).toBe(false)

  // Get the Input element by its implicit ARIA role.
  const recommendInput = getByRole('checkbox')
github testing-library / vue-testing-library / src / __tests__ / form.js View on Github external
const {
    getByLabelText,
    getByText,
    getByRole,
    getByPlaceholderText,
    emitted,
  } = render(Form)

  const submitButton = getByText('Submit')

  // Initially the submit button should be disabled.
  expect(submitButton).toBeDisabled()

  const titleInput = getByLabelText(/title of the movie/i)
  await fireEvent.update(titleInput, fakeReview.title)

  const reviewTextarea = getByPlaceholderText('Write an awesome review')
  await fireEvent.update(reviewTextarea, fakeReview.review)

  // Rating Radio buttons.
  const initiallySelectedInput = getByLabelText('Awful')
  const ratingSelect = getByLabelText('Wonderful')

  expect(initiallySelectedInput.checked).toBe(true)
  expect(ratingSelect.checked).toBe(false)

  await fireEvent.update(ratingSelect)

  expect(ratingSelect.checked).toBe(true)
  expect(initiallySelectedInput.checked).toBe(false)
github testing-library / vue-testing-library / src / __tests__ / form.js View on Github external
const initiallySelectedInput = getByLabelText('Awful')
  const ratingSelect = getByLabelText('Wonderful')

  expect(initiallySelectedInput.checked).toBe(true)
  expect(ratingSelect.checked).toBe(false)

  await fireEvent.update(ratingSelect)

  expect(ratingSelect.checked).toBe(true)
  expect(initiallySelectedInput.checked).toBe(false)

  // Get the Input element by its implicit ARIA role.
  const recommendInput = getByRole('checkbox')

  expect(recommendInput.checked).toBe(false)
  await fireEvent.update(recommendInput)
  expect(recommendInput.checked).toBe(true)

  // Make sure the submit button is enabled.
  expect(submitButton).toBeEnabled()
  expect(submitButton).toHaveAttribute('type', 'submit')

  await fireEvent.click(submitButton)

  // Assert the right event has been emitted.
  expect(emitted()).toHaveProperty('submit')
  expect(emitted().submit[0][0]).toMatchObject(fakeReview)
})
github testing-library / vue-testing-library / src / __tests__ / form.js View on Github external
expect(submitButton).toBeDisabled()

  const titleInput = getByLabelText(/title of the movie/i)
  await fireEvent.update(titleInput, fakeReview.title)

  const reviewTextarea = getByPlaceholderText('Write an awesome review')
  await fireEvent.update(reviewTextarea, fakeReview.review)

  // Rating Radio buttons.
  const initiallySelectedInput = getByLabelText('Awful')
  const ratingSelect = getByLabelText('Wonderful')

  expect(initiallySelectedInput.checked).toBe(true)
  expect(ratingSelect.checked).toBe(false)

  await fireEvent.update(ratingSelect)

  expect(ratingSelect.checked).toBe(true)
  expect(initiallySelectedInput.checked).toBe(false)

  // Get the Input element by its implicit ARIA role.
  const recommendInput = getByRole('checkbox')

  expect(recommendInput.checked).toBe(false)
  await fireEvent.update(recommendInput)
  expect(recommendInput.checked).toBe(true)

  // Make sure the submit button is enabled.
  expect(submitButton).toBeEnabled()
  expect(submitButton).toHaveAttribute('type', 'submit')

  await fireEvent.click(submitButton)
github testing-library / vue-testing-library / src / __tests__ / fire-event.js View on Github external
test('fireEvent.update does not crash if non-input element is passed in', async () =&gt; {
  const {getByText} = render({
    template: `<div>Hi</div>`,
  })

  await fireEvent.update(getByText('Hi'))

  expect(getByText('Hi')).toMatchInlineSnapshot(`
    <div>
      Hi
    </div>
  `)
})