Skip to content

Commit 299d78c

Browse files
committed
test: add unit tests for onKeyDown prop in ListBox component
1 parent f1d2493 commit 299d78c

File tree

1 file changed

+16
-0
lines changed

1 file changed

+16
-0
lines changed

packages/react-aria-components/test/ListBox.test.js

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1861,4 +1861,20 @@ describe('ListBox', () => {
18611861
expect(onClick).toHaveBeenCalledTimes(1);
18621862
});
18631863
});
1864+
1865+
describe('onKeyDown', () => {
1866+
it('should call onKeyDown handler when key is pressed on item', () => {
1867+
let onKeyDown = jest.fn();
1868+
let {getAllByRole} = renderListbox({}, {onKeyDown});
1869+
let options = getAllByRole('option');
1870+
1871+
fireEvent.keyDown(options[0], {key: 'Delete'});
1872+
expect(onKeyDown).toHaveBeenCalledTimes(1);
1873+
expect(onKeyDown.mock.calls[0][0]).toHaveProperty('key', 'Delete');
1874+
1875+
fireEvent.keyDown(options[1], {key: 'Backspace'});
1876+
expect(onKeyDown).toHaveBeenCalledTimes(2);
1877+
expect(onKeyDown.mock.calls[1][0]).toHaveProperty('key', 'Backspace');
1878+
});
1879+
});
18641880
});

0 commit comments

Comments
 (0)