score:3

Accepted answer
import useKeyPress from './../../src/component/useKeyPress/useKeyPress';
import { renderHook, act } from '@testing-library/react-hooks'
import {fireEvent} from '@testing-library/react'


test('Fire Enter keyboard event', () => {
    const { result } = renderHook((() => useKeyPress()))

    act(() => {
        fireEvent.keyDown(window, { key: 'Enter', code: 'Enter' });
    })
    expect(result.current.keyPress).toBe('Enter');
});

Related Query

More Query from same tag