import React from 'react'; import ConfigProvider from '..'; import { fireEvent, pureRender } from '../../../tests/utils'; import Tooltip from '../../tooltip'; interface Props { spy: () => void; } // https://github.com/ant-design/ant-design/issues/27617 describe('ConfigProvider', () => { const Child: React.FC = ({ spy }) => { React.useEffect(() => spy()); return
; }; const Sibling: React.FC = ({ spy }) => ( ); it('should not generate new context config when render', () => { const MemoedSibling = React.memo(Sibling); const spy = jest.fn(); const App: React.FC = () => { const [flex, setFlex] = React.useState({ vertical: true }); const [, forceRender] = React.useReducer((v) => v + 1, 1); return ( ); }; const { container } = pureRender(); const startCalledTimes = spy.mock.calls.length; fireEvent.click(container.querySelector('.render')!); expect(spy.mock.calls.length).toEqual(startCalledTimes); fireEvent.click(container.querySelector('.setState')!); expect(spy.mock.calls.length).toEqual(startCalledTimes + 1); }); it('should not generate new context config in nested ConfigProvider when render', () => { const MemoedSibling = React.memo(Sibling); const spy = jest.fn(); const App: React.FC = () => { const [flex, setFlex] = React.useState({ vertical: true }); const [, forceRender] = React.useReducer((v) => v + 1, 1); return ( ); }; const { container } = pureRender(); const startCalledTimes = spy.mock.calls.length; fireEvent.click(container.querySelector('.render')!); expect(spy.mock.calls.length).toEqual(startCalledTimes); fireEvent.click(container.querySelector('.setState')!); expect(spy.mock.calls.length).toEqual(startCalledTimes + 1); }); });