Skip to content

Commit

Permalink
test: add unit tests
Browse files Browse the repository at this point in the history
  • Loading branch information
meteorlxy committed Aug 13, 2024
1 parent c95dae1 commit c2e292a
Showing 1 changed file with 33 additions and 0 deletions.
33 changes: 33 additions & 0 deletions packages/components/src/text-control/test/text-control.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
* External dependencies
*/
import { render, screen } from '@testing-library/react';
import userEvent from '@testing-library/user-event';

/**
* Internal dependencies
Expand Down Expand Up @@ -59,6 +60,38 @@ describe( 'TextControl', () => {
} );
} );

describe( 'When a type prop is provided', () => {
it( 'should return string onChange', async () => {
const mockOnChange = jest.fn();

render(
<TextControl type="text" onChange={ mockOnChange } value="" />
);

await userEvent.type( screen.getByRole( 'textbox' ), '6' );

expect( mockOnChange ).toHaveBeenCalledTimes( 1 );
expect( mockOnChange ).toHaveBeenLastCalledWith( '6' );
} );

it( 'should return number onChange', async () => {
const mockOnChange = jest.fn();

render(
<TextControl
type="number"
onChange={ mockOnChange }
value={ 0 }
/>
);

await userEvent.type( screen.getByRole( 'spinbutton' ), '6' );

expect( mockOnChange ).toHaveBeenCalledTimes( 1 );
expect( mockOnChange ).toHaveBeenLastCalledWith( 6 );
} );
} );

describe( 'Check typings', () => {
// eslint-disable-next-line jest/expect-expect
it( 'should infer the value type from `type` prop', () => {
Expand Down

0 comments on commit c2e292a

Please sign in to comment.