diff --git a/components/grid/__tests__/cached-row-context.test.tsx b/components/grid/__tests__/cached-row-context.test.tsx
index 9a61f3747d..18b7f79b0f 100644
--- a/components/grid/__tests__/cached-row-context.test.tsx
+++ b/components/grid/__tests__/cached-row-context.test.tsx
@@ -1,48 +1,38 @@
-import React, { memo, useContext, useRef, useState } from 'react';
+import React, { memo, useContext } from 'react';
import Row from '../row';
import RowContext from '../RowContext';
-import { render, fireEvent } from '../../../tests/utils';
+import { fireEvent, pureRender } from '../../../tests/utils';
-const CacheInner = memo(() => {
- const countRef = useRef(0);
- countRef.current++;
- useContext(RowContext);
- return (
-
- Child Rendering Count: {countRef.current}
-
- );
-});
+let innerCount = 0;
+let outerCount = 0;
-const CacheOuter = () => {
- const [count, setCount] = useState(1);
- const handleClick = () => {
- setCount(count + 1);
- };
- return (
-
-
- Parent Rendering Count: {count}
-
-
-
-
- );
+const handleClick = () => {
+ outerCount++;
};
-it('Cached RowContext is working', () => {
- const { container } = render();
- const childCount = container.querySelector('#child_count')?.textContent;
+const CacheInner: React.FC = memo(() => {
+ innerCount++;
+ useContext(RowContext);
+ return null;
+});
- 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);
+const CacheOuter: React.FC = memo(() => (
+ <>
+
+
+
+
+ >
+));
+it('Cached RowContext is working', () => {
+ const { container, unmount } = pureRender();
+ expect(outerCount).toBe(0);
+ expect(innerCount).toBe(1);
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);
+ expect(outerCount).toBe(1);
+ expect(innerCount).toBe(1);
+ unmount();
});