ant-design/components/config-provider/__tests__/useSize.test.tsx
lijianan 9d1854763d
refactor: add useSize replace React.useContext (#42282)
* refactor: add useSize

* fix

* fix

* fix

* fix

* fix
2023-05-12 14:53:47 +08:00

18 lines
789 B
TypeScript

import React from 'react';
import { render } from '../../../tests/utils';
import useSize from '../hooks/useSize';
describe('useSize', () => {
it('useSize', () => {
const Demo: React.FC<{ size?: any }> = ({ size }) => <div>{useSize(size)}</div>;
const { container, rerender } = render(<Demo />);
expect(container.querySelector<HTMLDivElement>('div')?.textContent).toBe('');
rerender(<Demo size="test-size1" />);
expect(container.querySelector<HTMLDivElement>('div')?.textContent).toBe('test-size1');
rerender(<Demo size={() => 'test-size2'} />);
expect(container.querySelector<HTMLDivElement>('div')?.textContent).toBe('test-size2');
rerender(<Demo size={1} />);
expect(container.querySelector<HTMLDivElement>('div')?.textContent).toBe('');
});
});