import React from 'react'; import { act } from '@testing-library/react'; import { HotTable } from '../src/hotTable'; import { createSpreadsheetData, mockElementDimensions, simulateMouseEvent, mountComponentWithRef } from './_helpers'; import { HotRendererProps, HotTableRef } from '../src/types' describe('Using hooks within HotTable', () => { it('should be possible to use hook-enabled components as renderers', async () => { function HookEnabledRenderer(props: HotRendererProps) { const [count, setCount] = React.useState(0); return (

{props.value}

: {count}
); } const hotInstance = mountComponentWithRef(( )).hotInstance!; expect(hotInstance.getCell(0, 0)!.querySelectorAll('.hook-enabled-renderer-container').length).toEqual(1); expect(hotInstance.getCell(1, 1)!.querySelectorAll('.hook-enabled-renderer-container').length).toEqual(1); await act(async () => { simulateMouseEvent(hotInstance.getCell(0, 0)!.querySelector('button'), 'click'); }); await act(async () => { simulateMouseEvent(hotInstance.getCell(0, 0)!.querySelector('button'), 'click'); }); await act(async () => { simulateMouseEvent(hotInstance.getCell(0, 0)!.querySelector('button'), 'click'); }); expect(hotInstance.getCell(0, 0)!.querySelector('span')!.innerHTML).toEqual('3'); expect(hotInstance.getCell(1, 1)!.querySelector('span')!.innerHTML).toEqual('0'); }); /* Editor components are always used with React Hooks as they need to use useHotEditorHooks - tested everywhere else. */ });