Skip to content

Commit

Permalink
Ref tests (#3624)
Browse files Browse the repository at this point in the history
  • Loading branch information
melloware authored Nov 13, 2022
1 parent 0980c74 commit fa687fd
Show file tree
Hide file tree
Showing 2 changed files with 34 additions and 0 deletions.
17 changes: 17 additions & 0 deletions components/lib/inputtext/InputText.spec.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import '@testing-library/jest-dom';
import { fireEvent, render } from '@testing-library/react';
import userEvent from '@testing-library/user-event';
import * as React from 'react';
import { InputText } from './InputText';

describe('InputText', () => {
Expand Down Expand Up @@ -109,4 +110,20 @@ describe('InputText', () => {
expect(input).toHaveValue('');
expect(pasteOn).toHaveBeenCalledTimes(1);
});
test('when input is using onInput make sure it is called', async () => {
// Arrange
const inputOn = jest.fn();
const ref = React.createRef();
const { container } = render(<InputText ref={ref} onInput={inputOn} />);
const input = container.getElementsByTagName('input')[0];

// Act
ref.current.value = 'Jest testing value';
input.focus();
await userEvent.paste(' abc');

// Assert
expect(input).toHaveValue('Jest testing value abc');
expect(inputOn).toHaveBeenCalledTimes(1);
});
});
17 changes: 17 additions & 0 deletions components/lib/inputtextarea/InputTextarea.spec.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import '@testing-library/jest-dom';
import { fireEvent, render } from '@testing-library/react';
import userEvent from '@testing-library/user-event';
import * as React from 'react';
import { InputTextarea } from './InputTextarea';

describe('InputTextarea', () => {
Expand Down Expand Up @@ -121,4 +122,20 @@ describe('InputTextarea', () => {
expect(input).toHaveValue('');
expect(pasteOn).toHaveBeenCalledTimes(1);
});
test('when input is using onInput make sure it is called', async () => {
// Arrange
const inputOn = jest.fn();
const ref = React.createRef();
const { container } = render(<InputTextarea ref={ref} onInput={inputOn} />);
const input = container.getElementsByTagName('textarea')[0];

// Act
ref.current.value = 'Jest testing value';
input.focus();
await userEvent.paste(' abc');

// Assert
expect(input).toHaveValue('Jest testing value abc');
expect(inputOn).toHaveBeenCalledTimes(1);
});
});

0 comments on commit fa687fd

Please sign in to comment.