Posted 11 August 2020, 9:09 pm EST
Hi, I’m trying to get a selectionChanged event to fire in my Jest / React Testing Library test. I’m able to find grid cells and then click them, but the selectionChanged event doesn’t seem to fire. Below is my code. Do you know if it’s possible to use the click event? Or maybe there is some other way? Thanks!
/** * @jest-environment jsdom-sixteen */
import '@grapecity/wijmo.styles/wijmo.css';
import React from 'react';
import {
FlexGrid,
FlexGridColumn,
} from '@grapecity/wijmo.react.grid';
import {render, screen, waitFor, waitForDomChange} from '@testing-library/react';
import userEvent from '@testing-library/user-event';
const mockRowData = [{"pk":1,"shortName":"Burrito Short","longName":"Burrito Long"},
{"pk":2,"shortName":"Taco Short","longName":"Taco Long"}
];
it('should render row data on the screen and fire selection changed event', async () => {
const onSelectionChanged = jest.fn();
render(
<FlexGrid virtualizationThreshold={ [100, 100] }
itemsSource={mockRowData}
selectionChanged={onSelectionChanged}
selectionMode={'Row'}
>
<FlexGridColumn header="Pri Key" binding="pk" width={100} />
<FlexGridColumn header="Short Name" binding="shortName" width={100} />
<FlexGridColumn header="Long Name" binding="longName" width={100} />
</FlexGrid>
);
let node = await screen.findByText(/Taco Short/i);
userEvent.click(node);
node = await screen.findByText(/Burrito Long/i);
userEvent.click(node);
expect(onSelectionChanged).toHaveBeenCalledTimes(1);
});