mirror of
https://github.com/ant-design/ant-design.git
synced 2024-12-17 10:28:06 +08:00
81aac069ac
* test: move test cases to testing-library for Grid * fix: test when typeof gutter is object array in large screen
49 lines
1.4 KiB
TypeScript
49 lines
1.4 KiB
TypeScript
import React, { memo, useContext, useRef, useState } from 'react';
|
|
import Row from '../row';
|
|
import RowContext from '../RowContext';
|
|
import { render, fireEvent } from '../../../tests/utils';
|
|
|
|
const CacheInner = memo(() => {
|
|
const countRef = useRef(0);
|
|
countRef.current++;
|
|
useContext(RowContext);
|
|
return (
|
|
<div>
|
|
Child Rendering Count: <span id="child_count">{countRef.current}</span>
|
|
</div>
|
|
);
|
|
});
|
|
|
|
const CacheOuter = () => {
|
|
const [count, setCount] = useState(1);
|
|
const handleClick = () => {
|
|
setCount(count + 1);
|
|
};
|
|
return (
|
|
<div>
|
|
<button type="button" onClick={handleClick} id="parent_btn">
|
|
Click
|
|
</button>
|
|
Parent Rendering Count: <span id="parent_count">{count}</span>
|
|
<Row>
|
|
<CacheInner />
|
|
</Row>
|
|
</div>
|
|
);
|
|
};
|
|
|
|
it('Cached RowContext is working', () => {
|
|
const { container } = render(<CacheOuter />);
|
|
const childCount = container.querySelector('#child_count')?.textContent;
|
|
|
|
fireEvent.click(container.querySelector('#parent_btn')!);
|
|
expect(container.querySelector('#parent_count')?.textContent).toBe('2');
|
|
// child component won't rerender
|
|
expect(container.querySelector('#child_count')?.textContent).toBe(childCount);
|
|
|
|
fireEvent.click(container.querySelector('#parent_btn')!);
|
|
expect(container.querySelector('#parent_count')?.textContent).toBe('3');
|
|
// child component won't rerender
|
|
expect(container.querySelector('#child_count')?.textContent).toBe(childCount);
|
|
});
|