|
7 | 7 | */
|
8 | 8 |
|
9 | 9 | import React from 'react';
|
10 |
| -import { act } from 'react-dom/test-utils'; |
| 10 | +import { act } from '@testing-library/react'; |
11 | 11 | import { shallow, mount, ShallowWrapper, ReactWrapper } from 'enzyme';
|
12 | 12 | import { testCustomHook } from '../../../test/internal';
|
13 | 13 |
|
@@ -310,10 +310,19 @@ describe('useDataGridDisplaySelector', () => {
|
310 | 310 | component
|
311 | 311 | .find('input[type="range"][data-test-subj="lineCountNumber"]')
|
312 | 312 | .prop('value');
|
313 |
| - const setLineCountNumber = (component: ReactWrapper, number: number) => |
314 |
| - component |
315 |
| - .find('input[type="range"][data-test-subj="lineCountNumber"]') |
316 |
| - .simulate('change', { target: { value: number } }); |
| 313 | + const setLineCountNumber = ( |
| 314 | + component: ReactWrapper, |
| 315 | + number: number |
| 316 | + ) => { |
| 317 | + const input = component.find( |
| 318 | + 'input[type="range"][data-test-subj="lineCountNumber"]' |
| 319 | + ); |
| 320 | + |
| 321 | + // enzyme simulate() doesn't handle event.currentTarget updates well |
| 322 | + // https://github.com/enzymejs/enzyme/issues/218 |
| 323 | + (input.getDOMNode() as HTMLInputElement).value = number.toString(); |
| 324 | + input.simulate('change'); |
| 325 | + }; |
317 | 326 |
|
318 | 327 | it('conditionally displays a line count number input when the lineCount button is selected', () => {
|
319 | 328 | const component = mount(<MockComponent />);
|
@@ -357,7 +366,11 @@ describe('useDataGridDisplaySelector', () => {
|
357 | 366 | );
|
358 | 367 | openPopover(component);
|
359 | 368 |
|
360 |
| - setLineCountNumber(component, 3); |
| 369 | + act(() => { |
| 370 | + setLineCountNumber(component, 3); |
| 371 | + }); |
| 372 | + component.update(); |
| 373 | + |
361 | 374 | expect(getLineCountNumber(component)).toEqual(3);
|
362 | 375 | });
|
363 | 376 |
|
|
0 commit comments