/* eslint-disable no-console */ import React, { useState } from 'react'; import Space from '..'; import mountTest from '../../../tests/shared/mountTest'; import rtlTest from '../../../tests/shared/rtlTest'; import { fireEvent, render } from '../../../tests/utils'; import ConfigProvider from '../../config-provider'; describe('Space', () => { mountTest(Space); rtlTest(Space); it('should render width empty children', () => { const { container } = render(); expect(container.children.length).toBe(0); }); it('should render width ConfigProvider', () => { const { container } = render( 1 2 1 2 1 2 , ); expect(container.children).toMatchSnapshot(); }); it('should render width ConfigProvider support 0', () => { const { container } = render( 1 2 , ); const item = container.querySelector('.ant-space-gap-row-small.ant-space-gap-col-small'); expect(item).toBe(null); }); it('should render width rtl', () => { const { container } = render( 1 2 1 2 1 2 , ); expect(container.children).toMatchSnapshot(); }); it('should render width customize size', () => { const { container } = render( 1 2 , ); const items = container.querySelectorAll('div.ant-space-item'); expect(items[0]?.style.marginRight).toBe(''); expect(items[1]?.style.marginRight).toBe(''); }); it('should render vertical space width customize size', () => { const { container } = render( 1 2 , ); const items = container.querySelectorAll('div.ant-space-item'); expect(items[0]?.style.marginBottom).toBe(''); expect(items[1]?.style.marginBottom).toBe(''); }); it('should render correct with children', () => { const { container } = render( text1text1 {/* eslint-disable-next-line react/jsx-no-useless-fragment */} <>text3 , ); expect(container.children[0]).toMatchSnapshot(); }); it('should render with invalidElement', () => { const { container } = render( text1text1 text1 , ); expect(container.querySelectorAll('div.ant-space-item').length).toBe(3); }); it('should be keep store', () => { function Demo() { const [state, setState] = React.useState(1); return (
{ setState((value) => value + 1); }} > {state}
); } function SpaceDemo() { const [visible, setVisible] = useState(true); function onChange() { setVisible(!visible); } return ( {visible &&
space
}

Three

); } const { container } = render(); expect(container.querySelector('#demo')).toHaveTextContent('1'); fireEvent.click(container.querySelector('#demo')!); expect(container.querySelector('#demo')).toHaveTextContent('2'); fireEvent.click(container.querySelector('p')!); expect(container.querySelector('#demo')).toHaveTextContent('2'); }); it('split', () => { const { container } = render( text1text1 {/* eslint-disable-next-line react/jsx-no-useless-fragment */} <>text3 , ); expect(container.children[0]).toMatchSnapshot(); }); // https://github.com/ant-design/ant-design/issues/35305 it('should not throw duplicated key warning', () => { const spy = jest.spyOn(console, 'error').mockImplementation(() => {}); render(
, ); expect(spy).not.toHaveBeenCalledWith( expect.stringContaining('Encountered two children with the same key'), expect.anything(), expect.anything(), ); spy.mockRestore(); }); it('should render the hidden empty item wrapper', () => { const Null: React.FC = () => null; const { container } = render( , ); const element = container.querySelector('div.ant-space-item')!; expect(element).toBeEmptyDOMElement(); expect(getComputedStyle(element).display).toBe('none'); }); it('should ref work', () => { const ref = React.createRef(); const { container } = render( Text1 Text2 , ); expect(ref.current).toBe(container.firstChild); }); it('should classNames work', () => { const { container } = render( Text1 Text2 , ); expect(container.querySelector('.ant-space-item.test-classNames')).toBeTruthy(); }); it('should styles work', () => { const { container } = render( Text1 Text2 , ); expect( container.querySelector('.ant-space-item')?.getAttribute('style'), ).toEqual('color: red;'); }); });