Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Open
jefersonvinicius-alive opened this issue Apr 27, 2022 · 0 comments

Comments

@jefersonvinicius-alive
Copy link

jefersonvinicius-alive commented Apr 27, 2022

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant