Skip to content

Commit

Permalink
Add missing object onChange unit test
Browse files Browse the repository at this point in the history
  • Loading branch information
ciampo committed Jun 20, 2024
1 parent 8afc3cd commit b0ba57e
Showing 1 changed file with 48 additions and 0 deletions.
48 changes: 48 additions & 0 deletions packages/components/src/custom-select-control/test/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -271,6 +271,54 @@ describe.each( [
expect( screen.getByRole( 'option', { name: /hint/i } ) ).toBeVisible();
} );

it( 'Should return object onChange', async () => {
const user = userEvent.setup();
const mockOnChange = jest.fn();

render(
<Component
{ ...props }
value={ props.options[ 0 ] }
onChange={ mockOnChange }
/>
);

await user.click(
screen.getByRole( 'button', {
expanded: false,
} )
);

// DIFFERENCE WITH V2: NOT CALLED
// expect( mockOnChange ).toHaveBeenNthCalledWith(
// 1,
// expect.objectContaining( {
// inputValue: '',
// isOpen: false,
// selectedItem: { key: 'flower1', name: 'violets' },
// type: '',
// } )
// );

await user.click(
screen.getByRole( 'option', {
name: 'aquamarine',
} )
);

expect( mockOnChange ).toHaveBeenNthCalledWith(
1,
expect.objectContaining( {
inputValue: '',
isOpen: false,
selectedItem: expect.objectContaining( {
name: 'aquamarine',
} ),
type: '__item_click__',
} )
);
} );

it( 'Should return selectedItem object when specified onChange', async () => {
const user = userEvent.setup();
const mockOnChange = jest.fn();
Expand Down

0 comments on commit b0ba57e

Please sign in to comment.