React Testing Library fireEvent.change example

April 09, 2020

Example -

import React from 'react';
import { cleanup, render, fireEvent } from '@testing-library/react';

import App from './App';

afterEach(cleanup);

it('Enter principal amount', async () => {
  const { getByTestId } = render(<App />);
  const principalInputElement = getByTestId('principalInput') as HTMLInputElement;
  fireEvent.change(principalInputElement, {target: {value: '20000'}});
  expect(getByTestId('emititle')).toHaveTextContent('1758');
});

Connect With Me!!

Get updates about React, React Native, NodeJs, Web Development, Freelancing and Business. No Spam.

+91 9922234778

kapilsg186@gmail.com

Kapil Gorve LinkedIn ProfileKapil Gorve Twitter AccountKapil Gorve Quora ProfileKapil Gorve Github Account