diff --git a/components/divider/__tests__/index.test.ts b/components/divider/__tests__/index.test.ts deleted file mode 100644 index 59763af9a4..0000000000 --- a/components/divider/__tests__/index.test.ts +++ /dev/null @@ -1,6 +0,0 @@ -import Divider from '..'; -import mountTest from '../../../tests/shared/mountTest'; - -describe('Divider', () => { - mountTest(Divider); -}); diff --git a/components/divider/__tests__/index.test.tsx b/components/divider/__tests__/index.test.tsx new file mode 100644 index 0000000000..0e581f43b2 --- /dev/null +++ b/components/divider/__tests__/index.test.tsx @@ -0,0 +1,17 @@ +import * as React from 'react'; +import { render } from '../../../tests/utils'; +import Divider from '..'; +import mountTest from '../../../tests/shared/mountTest'; + +describe('Divider', () => { + mountTest(Divider); + + it('not show children when vertical', () => { + const errSpy = jest.spyOn(console, 'error').mockImplementation(() => {}); + + const { container } = render(Bamboo); + expect(container.querySelector('.ant-divider-inner-text')).toBeFalsy(); + + errSpy.mockRestore(); + }); +}); diff --git a/components/divider/index.tsx b/components/divider/index.tsx index 700a116153..adac568f09 100644 --- a/components/divider/index.tsx +++ b/components/divider/index.tsx @@ -1,6 +1,7 @@ import classNames from 'classnames'; import * as React from 'react'; import { ConfigContext } from '../config-provider'; +import warning from '../_util/warning'; import useStyle from './style'; @@ -58,9 +59,18 @@ const Divider: React.FC = props => { ...(hasCustomMarginRight && { marginRight: orientationMargin }), }; + // Warning children not work in vertical mode + if (process.env.NODE_ENV !== 'production') { + warning( + !children || type !== 'vertical', + 'Divider', + '`children` not working in `vertical` mode.', + ); + } + return wrapSSR(
- {children && ( + {children && type !== 'vertical' && ( {children} diff --git a/components/form/__tests__/__snapshots__/index.test.js.snap b/components/form/__tests__/__snapshots__/index.test.tsx.snap similarity index 100% rename from components/form/__tests__/__snapshots__/index.test.js.snap rename to components/form/__tests__/__snapshots__/index.test.tsx.snap diff --git a/components/form/__tests__/index.test.js b/components/form/__tests__/index.test.tsx similarity index 93% rename from components/form/__tests__/index.test.js rename to components/form/__tests__/index.test.tsx index c4263bbbcb..6dafb1be3e 100644 --- a/components/form/__tests__/index.test.js +++ b/components/form/__tests__/index.test.tsx @@ -1,9 +1,9 @@ import { mount } from 'enzyme'; import React, { Component, useState } from 'react'; -import { act } from 'react-dom/test-utils'; import scrollIntoView from 'scroll-into-view-if-needed'; import classNames from 'classnames'; import Form from '..'; +import type { FormInstance } from '..'; import * as Util from '../util'; import Button from '../../button'; @@ -20,7 +20,7 @@ import TreeSelect from '../../tree-select'; import mountTest from '../../../tests/shared/mountTest'; import rtlTest from '../../../tests/shared/rtlTest'; -import { fireEvent, render, sleep } from '../../../tests/utils'; +import { fireEvent, render, sleep, act } from '../../../tests/utils'; import ConfigProvider from '../../config-provider'; import Drawer from '../../drawer'; import zhCN from '../../locale/zh_CN'; @@ -38,10 +38,10 @@ describe('Form', () => { rtlTest(Form); rtlTest(Form.Item); - scrollIntoView.mockImplementation(() => {}); + (scrollIntoView as any).mockImplementation(() => {}); const errorSpy = jest.spyOn(console, 'error').mockImplementation(() => {}); - async function change(container, index, value, executeMockTimer) { + async function change(container: Element, index: number, value: any, executeMockTimer: boolean) { fireEvent.change(container.querySelectorAll('input')[index], { target: { value }, }); @@ -59,7 +59,7 @@ describe('Form', () => { beforeEach(() => { jest.useRealTimers(); - scrollIntoView.mockReset(); + (scrollIntoView as any).mockReset(); }); afterEach(() => { @@ -68,7 +68,7 @@ describe('Form', () => { afterAll(() => { errorSpy.mockRestore(); - scrollIntoView.mockRestore(); + (scrollIntoView as any).mockRestore(); }); describe('noStyle Form.Item', () => { @@ -143,11 +143,11 @@ describe('Form', () => { const { container } = render(); await change(container, 0, '1', true); - expect(container.querySelector('.ant-form-item-explain').textContent).toEqual('aaa'); + expect(container.querySelector('.ant-form-item-explain')!.textContent).toEqual('aaa'); await change(container, 0, '2', true); - expect(container.querySelector('.ant-form-item-explain').textContent).toEqual('ccc'); + expect(container.querySelector('.ant-form-item-explain')!.textContent).toEqual('ccc'); await change(container, 0, '1', true); - expect(container.querySelector('.ant-form-item-explain').textContent).toEqual('aaa'); + expect(container.querySelector('.ant-form-item-explain')!.textContent).toEqual('aaa'); jest.useRealTimers(); }); @@ -356,9 +356,9 @@ describe('Form', () => { }); describe('scrollToField', () => { - function test(name, genForm) { + function test(name: string, genForm: () => { props: any; getForm: () => FormInstance }) { it(name, () => { - let callGetForm; + let callGetForm: () => FormInstance = undefined!; const Demo = () => { const { props, getForm } = genForm(); @@ -402,10 +402,10 @@ describe('Form', () => { // ref test('ref', () => { - let form; + let form: FormInstance; return { props: { - ref: instance => { + ref: (instance: FormInstance) => { form = instance; }, }, @@ -442,7 +442,7 @@ describe('Form', () => { it('Form.Item should support data-*、aria-* and custom attribute', () => { const wrapper = mount(
-