diff --git a/components/affix/__tests__/Affix.test.tsx b/components/affix/__tests__/Affix.test.tsx index b65684f8a6..67e2039199 100644 --- a/components/affix/__tests__/Affix.test.tsx +++ b/components/affix/__tests__/Affix.test.tsx @@ -3,7 +3,7 @@ import type { InternalAffixClass } from '..'; import Affix from '..'; import accessibilityTest from '../../../tests/shared/accessibilityTest'; import rtlTest from '../../../tests/shared/rtlTest'; -import { render, sleep, triggerResize } from '../../../tests/utils'; +import { render, sleep, triggerResize, waitFakeTimer } from '../../../tests/utils'; import Button from '../../button'; import { getObserverEntities } from '../utils'; @@ -216,22 +216,31 @@ describe('Affix Render', () => { }); // Trigger inner and outer element for the two s. - it.each([ - { selector: '.ant-btn' }, // inner - { selector: '.fixed' }, // outer - ])('trigger listener when size change', async ({ selector }) => { - const updateCalled = jest.fn(); - const { container } = render( - , - { - container: document.getElementById('mounter')!, - }, - ); + [ + '.ant-btn', // inner + '.fixed', // outer + ].forEach(selector => { + it(`trigger listener when size change: ${selector}`, async () => { + jest.useFakeTimers(); - updateCalled.mockReset(); - triggerResize(container.querySelector(selector)!); - await sleep(20); - expect(updateCalled).toHaveBeenCalled(); + const updateCalled = jest.fn(); + const { container } = render( + , + { + container: document.getElementById('mounter')!, + }, + ); + + updateCalled.mockReset(); + triggerResize(container.querySelector(selector)!); + + await waitFakeTimer(); + + expect(updateCalled).toHaveBeenCalled(); + + jest.clearAllTimers(); + jest.useRealTimers(); + }); }); }); }); 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..427a1cf6ea 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, waitFakeTimer } 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(
-