Skip to content

Error using InputCurrency with fireEvent.change and userEvent.type #1423

@jefersonvinicius-alive

Description

@jefersonvinicius-alive

Describe the bug
When I'am using the InputCurrency in tests I getting the error below:

Error: Uncaught [ReferenceError: event is not defined]

To Reproduce
Just run the tests below:

import { fireEvent, render, screen } from '@vtex/test-tools/react'
import React, { useState } from 'react'
import userEvent from '@testing-library/user-event'
import { InputCurrency } from 'vtex.styleguide'

function Sut() {
  const [value, setValue] = useState()

  return (
    <div>
      <InputCurrency
        testId="input-testid"
        name="input"
        locale="pt-BR"
        currencyCode="BRL"
        value={value}
        onChange={({ target }: any) => setValue(target.value)}
      />
      <span data-testid="raw-value-span">Raw Value: {value}</span>
    </div>
  )
}

test('currency input with fireEvent.change', async () => {
  render(<Sut />)

  const input = screen.getByTestId('input-testid')
  const nativeInput = input.querySelector('input[name="input"]')

  fireEvent.change(nativeInput!, { target: { value: '1' } })

  expect(screen.getByTestId('raw-value-span')).toHaveTextContent('Raw Value: 1')
})

test('currency input with userEvent.type', async () => {
  render(<Sut />)

  const input = screen.getByTestId('input-testid')
  const nativeInput = input.querySelector('input[name="input"]')

  userEvent.type(nativeInput!, '2')

  expect(screen.getByTestId('raw-value-span')).toHaveTextContent('Raw Value: 2')
})

Expected behavior
The tests pass

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

      Development

      No branches or pull requests

        Participants

        @jefersonvinicius-alive

        Issue actions

          Error using InputCurrency with fireEvent.change and userEvent.type · Issue #1423 · vtex/styleguide