diff --git a/.github/workflows/ui-upload.yml b/.github/workflows/ui-upload.yml index f2470f4dc4..e2f694af3a 100644 --- a/.github/workflows/ui-upload.yml +++ b/.github/workflows/ui-upload.yml @@ -52,12 +52,11 @@ jobs: path: imageSnapshots - name: Install - run: npm i fast-glob lodash argos-cli + run: npm i fast-glob lodash @argos-ci/core - - name: Upload argos-ci + - name: Upload on Argos id: deploy run: npm run argos env: ARGOS_TOKEN: ${{ secrets.ARGOS_TOKEN }} - ARGOS_GITHUB_BRANCH: ${{ steps.branch.outputs.id }} - ARGOS_GITHUB_COMMIT: ${{ steps.commit.outputs.id }} + ARGOS_PARALLEL_NONCE: ${{ github.run_id }} diff --git a/.github/workflows/ui.yml b/.github/workflows/ui.yml index be7cdf6d24..293b934a14 100644 --- a/.github/workflows/ui.yml +++ b/.github/workflows/ui.yml @@ -16,6 +16,8 @@ jobs: steps: - name: checkout uses: actions/checkout@v3 + with: + fetch-depth: 2 - name: cache package-lock.json uses: actions/cache@v3 diff --git a/.github/workflows/verify-files-modify.yml b/.github/workflows/verify-files-modify.yml index 93c6578ff9..7a661cacf6 100644 --- a/.github/workflows/verify-files-modify.yml +++ b/.github/workflows/verify-files-modify.yml @@ -19,6 +19,7 @@ jobs: forbid-paths: '.github/, scripts/' forbid-files: 'CHANGELOG.zh-CN.md, CHANGELOG.en-US.md, LICENSE' skip-verify-authority: 'write' + skip-label: 'skip-verify-files' assignees: 'afc163, zombieJ, xrkffgg, MadCcc' comment-mark: 'version' comment: | diff --git a/.jest.js b/.jest.js index 1e96c6f9ab..b9434c048d 100644 --- a/.jest.js +++ b/.jest.js @@ -44,6 +44,7 @@ module.exports = { '!components/*/__tests__/type.test.tsx', '!components/**/*/interface.{ts,tsx}', '!components/*/__tests__/image.test.{ts,tsx}', + '!components/__tests__/node.test.tsx', ], transformIgnorePatterns, snapshotSerializers: ['enzyme-to-json/serializer'], diff --git a/.jest.node.js b/.jest.node.js index 4e79459c59..341226e400 100644 --- a/.jest.node.js +++ b/.jest.node.js @@ -12,8 +12,7 @@ module.exports = { '\\.md$': './node_modules/@ant-design/tools/lib/jest/demoPreprocessor', '\\.(jpg|png|gif|svg)$': './node_modules/@ant-design/tools/lib/jest/imagePreprocessor', }, - testRegex: 'demo\\.test\\.(j|t)s$', + testRegex: 'node\\.test\\.(j|t)sx$', testEnvironment: 'node', transformIgnorePatterns, - snapshotSerializers: ['enzyme-to-json/serializer'], }; diff --git a/CHANGELOG.en-US.md b/CHANGELOG.en-US.md index f96db93e9f..621df38085 100644 --- a/CHANGELOG.en-US.md +++ b/CHANGELOG.en-US.md @@ -15,6 +15,27 @@ timeline: true --- +## 4.23.2 + +`2022-09-17` + +- 🐞 Fix Card console warning when using `tabList` prop. [#37537](https://github.com/ant-design/ant-design/pull/37537) [@edc-hui](https://github.com/edc-hui) +- 🐞 Fix Table `filterSearch` is not executed when `filterMode="tree"`. [#37587](https://github.com/ant-design/ant-design/pull/37587) [@edc-hui](https://github.com/edc-hui) +- 🐞 Fix Tooltip should not replace children `className` when it's not a string type. [#37598](https://github.com/ant-design/ant-design/pull/37598) +- 🐞 Fix Tree that TreeNodes not aligned when draggable and some node is disabled. [#37534](https://github.com/ant-design/ant-design/pull/37534) +- TypeScript + - 🤖 Replace deprecated `React.ReactChild` type. [#37551](https://github.com/ant-design/ant-design/pull/37551) [@bowen-wu](https://github.com/bowen-wu) + +## 4.23.1 + +`2022-09-09` + +- 🐞 Fix unable to close modal when using visible in `Modal.confirm().update`. [#37471](https://github.com/ant-design/ant-design/pull/37471) [@Aaron674092290](https://github.com/Aaron674092290) +- 🐞 Fix esbuild strict mode call `No matching export theme` error. [#37462](https://github.com/ant-design/ant-design/pull/37462) +- 🐞 Fix Switch background flush issue by reverting [#35103](https://github.com/ant-design/ant-design/pull/35103). [#37458](https://github.com/ant-design/ant-design/pull/37458) +- TypeScript + - 🤖 InputNumber `value` add null type. [#37421](https://github.com/ant-design/ant-design/pull/37421) [@li-jia-nan](https://github.com/li-jia-nan) + ## 4.23.0 `2022-09-04` @@ -30,7 +51,7 @@ timeline: true - 🛠 Table changes `filterDropdownVisible` to `filterDropdownOpen`. [#37026](https://github.com/ant-design/ant-design/pull/37026) [@yykoypj](https://github.com/yykoypj) - 🛠 Slider add `tooltip` prop for all props related with Tooltip. [#37000](https://github.com/ant-design/ant-design/pull/37000) [@yykoypj](https://github.com/yykoypj) - 🛠 Tooltip Popover and Popconfirm change `visible` to `open`. [#37241](https://github.com/ant-design/ant-design/pull/37241) [@yykoypj](https://github.com/yykoypj) - - 🛠 Remove `visible` prop of Tag. [#36934](https://github.com/ant-design/ant-design/pull/36934) [@yykoypj](https://github.com/yykoypj) + - 🛠 Deprecate `visible` prop of Tag. [#36934](https://github.com/ant-design/ant-design/pull/36934) [@yykoypj](https://github.com/yykoypj) - 🛠 Deprecate `dropdownClassName` prop of all components and change to `popupClassName`. [#36880](https://github.com/ant-design/ant-design/pull/36880) [@heiyu4585](https://github.com/heiyu4585) - 🛠 Tabs support `items` props and origin jsx usage will be depreacted. [#36889](https://github.com/ant-design/ant-design/pull/36889) - 🐞 Fix that some css variables are not consistent with less variables. @@ -44,8 +65,6 @@ timeline: true - 🌐 Add missing translations for filterCheckall in ru_RU. [#37311](https://github.com/ant-design/ant-design/pull/37311) [@HelLuv](https://github.com/HelLuv) - 🌐 Add missing translations in `cs_CZ`. [#37388](https://github.com/ant-design/ant-design/pull/37388) [@ZdenekKrcal](https://github.com/ZdenekKrcal) ---- - ## 4.22.8 `2022-08-26` @@ -194,7 +213,7 @@ timeline: true - 💄 Fix nested Table margin style. [#36209](https://github.com/ant-design/ant-design/pull/36209) - 🐞 Fix Table filter dropdown with multiple subMenu may not closed. [#36132](https://github.com/ant-design/ant-design/pull/36132) - 🐞 Table reset the last selection key when deselect or bulk operations. [#34705](https://github.com/ant-design/ant-design/pull/34705) [@Dunqing](https://github.com/Dunqing) -- 🐞 Fix Popover arrow color with custom `color` prop. [#36241](https://github.com/ant-design/ant-design/pull/36241) [@MadCcc](https://github.com/MadCcc) +- 🐞 Fix Popover arrow color with custom `color` prop. [#36241](https://github.com/ant-design/ant-design/pull/36241) - 🐞 Fix Upload `listType="picture-card"` select button not being hidden when children is empty. [#36196](https://github.com/ant-design/ant-design/pull/36196) - 🐞 Fix Menu deprecated warning when `item={undefined}`. [#36190](https://github.com/ant-design/ant-design/pull/36190) - 💄 Fix Button `loading` icon margin style lost. [#36168](https://github.com/ant-design/ant-design/pull/36168) @@ -417,7 +436,7 @@ timeline: true - Less - 💄 Replace less html selector with related variable. [#35186](https://github.com/ant-design/ant-design/pull/35186) [@jeffdrumgod](https://github.com/jeffdrumgod) - 💄 Modify less `danger` value from the function to variable. [#35113](https://github.com/ant-design/ant-design/pull/35113) [@TrickyPi](https://github.com/TrickyPi) - - 🐞 Arrow border radius variable use fixed value. [#35086](https://github.com/ant-design/ant-design/pull/35086) [@MadCcc](https://github.com/MadCcc) + - 🐞 Arrow border radius variable use fixed value. [#35086](https://github.com/ant-design/ant-design/pull/35086) - TypeScript - 🤖 Fixed `Upload` component `UploadChangeParam` internal `fileList` not using generics. [#35158](https://github.com/ant-design/ant-design/pull/35158) [@rendaoer](https://github.com/rendaoer) - 🤖 Update TypeScript definition for `@types/react@18` compatible. [#35075](https://github.com/ant-design/ant-design/pull/35075) [@AliRezaBeigy](https://github.com/AliRezaBeigy) [#35076](https://github.com/ant-design/ant-design/pull/35076) [@littledian](https://github.com/littledian) @@ -572,7 +591,7 @@ timeline: true - 💄 Improve Menu `:focus-visible` style. [#34008](https://github.com/ant-design/ant-design/pull/34008) - 💄 Fix Pagination and Rate style problem in Safari. [#34002](https://github.com/ant-design/ant-design/pull/34002) - 💄 Fix Row and Col component styles when using prefixCls. [#33969](https://github.com/ant-design/ant-design/pull/33969) [@mic-web](https://github.com/mic-web) -- 🐞 Fix Timeline icons with custom color not working. [#33951](https://github.com/ant-design/ant-design/pull/33951) [@MadCcc](https://github.com/MadCcc) +- 🐞 Fix Timeline icons with custom color not working. [#33951](https://github.com/ant-design/ant-design/pull/33951) - TypeScript - 🤖 Optimize Cascader `onChange` definition with `multiple` prop. [#33947](https://github.com/ant-design/ant-design/pull/33947) [@babycannotsay](https://github.com/babycannotsay) @@ -655,7 +674,7 @@ timeline: true `2021-12-29` -- 🐞 Fix Popconfirm throws `Can't perform a React state update on an unmounted component.` warning in some async case. [#33432](https://github.com/ant-design/ant-design/pull/33432) [@MadCcc](https://github.com/MadCcc) +- 🐞 Fix Popconfirm throws `Can't perform a React state update on an unmounted component.` warning in some async case. [#33432](https://github.com/ant-design/ant-design/pull/33432) - 🐞 Fix Input with `suffix` will crash when `value` is number type. [#33462](https://github.com/ant-design/ant-design/pull/33462) - 🐞 Fix Divider with text dashed border color error. [#33452](https://github.com/ant-design/ant-design/pull/33452) [@chen-jingjie](https://github.com/chen-jingjie) - 🐞 Fix Dropdown.Button not support `destroyPopupOnHide`. [#33442](https://github.com/ant-design/ant-design/pull/33442) [@LongHaoo](https://github.com/LongHaoo) diff --git a/CHANGELOG.zh-CN.md b/CHANGELOG.zh-CN.md index cf6b448e21..5e070e51e7 100644 --- a/CHANGELOG.zh-CN.md +++ b/CHANGELOG.zh-CN.md @@ -15,6 +15,27 @@ timeline: true --- +## 4.23.2 + +`2022-09-17` + +- 🐞 修复 Card 传入 `tabList` 属性时控制台出现废弃警告的问题。[#37537](https://github.com/ant-design/ant-design/pull/37537) [@edc-hui](https://github.com/edc-hui) +- 🐞 修复 Table `filterMode="tree"` 时 `filterSearch` 函数未执行的问题。[#37587](https://github.com/ant-design/ant-design/pull/37587) [@edc-hui](https://github.com/edc-hui) +- 🐞 修复 Tooltip 的子元素 `className` 非 string 类型时会被覆盖的问题。[#37598](https://github.com/ant-design/ant-design/pull/37598) +- 🐞 修复 Tree 组件 TreeNode 在可拖拽并且禁用状态下不对齐的问题。[#37534](https://github.com/ant-design/ant-design/pull/37534) +- TypeScript + - 🤖 替换已废弃的 `React.ReactChild` 定义。[#37551](https://github.com/ant-design/ant-design/pull/37551) [@bowen-wu](https://github.com/bowen-wu) + +## 4.23.1 + +`2022-09-09` + +- 🐞 修复 `Modal.confirm().update({visible: true})` 导致无法关闭 modal 的问题。[#37471](https://github.com/ant-design/ant-design/pull/37471) [@Aaron674092290](https://github.com/Aaron674092290) +- 🐞 兜底修复 esbuild 严格模式构建时报 `No matching export theme` 错误。[#37462](https://github.com/ant-design/ant-design/pull/37462) +- 🐞 回滚 [#35103](https://github.com/ant-design/ant-design/pull/35103) 以修复 Switch 切换时背景闪烁的问题。[#37458](https://github.com/ant-design/ant-design/pull/37458) +- TypeScript + - 🤖 InputNumber `value` 新增类型 null。[#37421](https://github.com/ant-design/ant-design/pull/37421) [@li-jia-nan](https://github.com/li-jia-nan) + ## 4.23.0 `2022-09-04` @@ -30,7 +51,7 @@ timeline: true - 🛠 Table 组件 `columns` 中的 `filterDropdownVisible` 改为 `filterDropdownOpen`。[#37026](https://github.com/ant-design/ant-design/pull/37026) [@yykoypj](https://github.com/yykoypj) - 🛠 Tooltip, Popover 和 Popconfirm 中的 `visible` 改为 `open`。[#37241](https://github.com/ant-design/ant-design/pull/37241) [@yykoypj](https://github.com/yykoypj) - 🛠 Slider 的 `tooltip` 相关属性合并到 `tooltip` 属性中。[#37000](https://github.com/ant-design/ant-design/pull/37000) [@yykoypj](https://github.com/yykoypj) - - 🛠 移除 Tag 组件的 `visible` 属性。[#36934](https://github.com/ant-design/ant-design/pull/36934) [@yykoypj](https://github.com/yykoypj) + - 🛠 废弃 Tag 组件的 `visible` 属性。[#36934](https://github.com/ant-design/ant-design/pull/36934) [@yykoypj](https://github.com/yykoypj) - 🛠 废弃所有组件的 `dropdownClassName`,统一为 `popupClassName`。[#36880](https://github.com/ant-design/ant-design/pull/36880) [@heiyu4585](https://github.com/heiyu4585) - 🛠 Tabs 支持 `items` 属性,并且废弃原 jsx 语法糖用法。[#36889](https://github.com/ant-design/ant-design/pull/36889) - 🐞 修复 css 变量与 less 变量不一致的问题。 @@ -44,8 +65,6 @@ timeline: true - 🌐 补全 `ru_RU` 中 `filterCheckall` 的翻译。[#37311](https://github.com/ant-design/ant-design/pull/37311) [@HelLuv](https://github.com/HelLuv) - 🌐 补全 `cs_CZ` 的翻译。[#37388](https://github.com/ant-design/ant-design/pull/37388) [@ZdenekKrcal](https://github.com/ZdenekKrcal) ---- - ## 4.22.8 `2022-08-26` @@ -195,7 +214,7 @@ timeline: true - 🐞 Table 取消选择或批量操作时重置上一次选择的 key。[#34705](https://github.com/ant-design/ant-design/pull/34705) [@Dunqing](https://github.com/Dunqing) - 🐞 修复 Table 过滤列表在某些场景下多级展开无法关闭的问题。[#36132](https://github.com/ant-design/ant-design/pull/36132) - 🐞 修复 Upload `listType="picture-card"` 当 children 为空时上传文件按钮没有隐藏的问题。[#36196](https://github.com/ant-design/ant-design/pull/36196) -- 🐞 修复 Popover 自定义 `color` 时箭头颜色问题。[#36241](https://github.com/ant-design/ant-design/pull/36241) [@MadCcc](https://github.com/MadCcc) +- 🐞 修复 Popover 自定义 `color` 时箭头颜色问题。[#36241](https://github.com/ant-design/ant-design/pull/36241) - 🐞 修复 Menu `item={undefined}` 时会有废弃警告的问题。[#36190](https://github.com/ant-design/ant-design/pull/36190) - 💄 修复 Button `loading` 图标的间距丢失的问题。[#36168](https://github.com/ant-design/ant-design/pull/36168) - 🐞 修复 Dropdown 中 Menu 分组下的 Item 点击不会关闭的问题。[#36148](https://github.com/ant-design/ant-design/pull/36148) @@ -413,12 +432,12 @@ timeline: true - 🐞 修复 Title、Text、Paragraph 组件不支持 `ref` 的问题。[#34847](https://github.com/ant-design/ant-design/pull/34847) [@MQuy](https://github.com/MQuy) - Input - 💄 Input.Group 对子组件屏蔽 Form.Item 的样式。[#34764](https://github.com/ant-design/ant-design/pull/34764) - - 💄 调整 Form 下 TextArea 的样式。[#34714](https://github.com/ant-design/ant-design/pull/34714) [@MadCcc](https://github.com/MadCcc) + - 💄 调整 Form 下 TextArea 的样式。[#34714](https://github.com/ant-design/ant-design/pull/34714) - ⌨️ 修复 Checkbox 缺少 `aria-checked` 属性导致屏幕阅读器识别错误的问题。[#34862](https://github.com/ant-design/ant-design/pull/34862) [@SpaNb4](https://github.com/SpaNb4) - Less - 💄 替换 less 中的 html 选择器为对应变量。[#35186](https://github.com/ant-design/ant-design/pull/35186) [@jeffdrumgod](https://github.com/jeffdrumgod) - 💄 修改 less 中 `danger` 值从函数改为变量。[#35113](https://github.com/ant-design/ant-design/pull/35113) [@TrickyPi](https://github.com/TrickyPi) - - 🐞 箭头圆角使用固定值 2px 变量。[#35086](https://github.com/ant-design/ant-design/pull/35086) [@MadCcc](https://github.com/MadCcc) + - 🐞 箭头圆角使用固定值 2px 变量。[#35086](https://github.com/ant-design/ant-design/pull/35086) - TypeScript - 🤖 修正 Upload 组件中 `UploadChangeParam` 内部 `fileList` 不使用泛型问题。[#35158](https://github.com/ant-design/ant-design/pull/35158) [@rendaoer](https://github.com/rendaoer) - 🤖 更新 TypeScript 定义以兼容 `@types/react@18`。[#35075](https://github.com/ant-design/ant-design/pull/35075) [@AliRezaBeigy](https://github.com/AliRezaBeigy) [#35076](https://github.com/ant-design/ant-design/pull/35076) [@littledian](https://github.com/littledian) @@ -574,7 +593,7 @@ timeline: true - 💄 优化 Menu `:focus-visible` 的样式。[#34008](https://github.com/ant-design/ant-design/pull/34008) - 💄 修复 Pagination 和 Rate 在 Safari 下部分样式丢失的问题,比如分页按钮禁用样式失效。[#34002](https://github.com/ant-design/ant-design/pull/34002) - 💄 修复 Row 与 Col 在配置 `prefixCls` 的样式问题。[#33969](https://github.com/ant-design/ant-design/pull/33969) [@mic-web](https://github.com/mic-web) -- 🐞 修复 Timeline 的自定义图标颜色无效的问题。[#33951](https://github.com/ant-design/ant-design/pull/33951) [@MadCcc](https://github.com/MadCcc) +- 🐞 修复 Timeline 的自定义图标颜色无效的问题。[#33951](https://github.com/ant-design/ant-design/pull/33951) - TypeScript - 🤖 优化 Cascader `multiple` 属性对应的 `onChange` 类型推断。[#33947](https://github.com/ant-design/ant-design/pull/33947) [@babycannotsay](https://github.com/babycannotsay) @@ -657,7 +676,7 @@ timeline: true `2021-12-29` -- 🐞 修复 Popconfirm 在某些情况下会出现 `Can't perform a React state update on an unmounted component.` 的错误。[#33432](https://github.com/ant-design/ant-design/pull/33432) [@MadCcc](https://github.com/MadCcc) +- 🐞 修复 Popconfirm 在某些情况下会出现 `Can't perform a React state update on an unmounted component.` 的错误。[#33432](https://github.com/ant-design/ant-design/pull/33432) - 🐞 修复 Input 配置 `suffix` 时 `value` 为数字类型会崩溃的问题。[#33462](https://github.com/ant-design/ant-design/pull/33462) - 🐞 修复 Divider with text dashed 的边框颜色错误问题。[#33452](https://github.com/ant-design/ant-design/pull/33452) [@chen-jingjie](https://github.com/chen-jingjie) - 🐞 修复 Dropdown.Button 不支持 `destroyPopupOnHide` 的问题。[#33442](https://github.com/ant-design/ant-design/pull/33442) [@LongHaoo](https://github.com/LongHaoo) diff --git a/components/__tests__/__snapshots__/index.test.ts.snap b/components/__tests__/__snapshots__/index.test.ts.snap index 3e17f31437..ea9484e31b 100644 --- a/components/__tests__/__snapshots__/index.test.ts.snap +++ b/components/__tests__/__snapshots__/index.test.ts.snap @@ -67,6 +67,7 @@ Array [ "Upload", "message", "notification", + "theme", "version", ] `; diff --git a/components/__tests__/node.test.tsx b/components/__tests__/node.test.tsx new file mode 100644 index 0000000000..ff197dec83 --- /dev/null +++ b/components/__tests__/node.test.tsx @@ -0,0 +1,48 @@ +import glob from 'glob'; +import * as React from 'react'; +import { renderToString } from 'react-dom/server'; +import type { Options } from '../../tests/shared/demoTest'; + +(global as any).testConfig = {}; + +jest.mock('../../tests/shared/demoTest', () => { + function fakeDemoTest(name: string, option: Options = {}) { + (global as any).testConfig[name] = option; + } + + return fakeDemoTest; +}); + +describe('node', () => { + beforeAll(() => { + jest.useFakeTimers().setSystemTime(new Date('2016-11-22')); + }); + + // Find the component exist demo test file + const files = glob.sync(`./components/*/__tests__/demo.test.@(j|t)s?(x)`); + + files.forEach(componentTestFile => { + const componentName = componentTestFile.match(/components\/([^/]*)\//)![1]; + + // Test for ssr + describe(componentName, () => { + const demoList = glob.sync(`./components/${componentName}/demo/*.md`); + + // Use mock to get config + require(`../../${componentTestFile}`); // eslint-disable-line global-require, import/no-dynamic-require + const option = (global as any).testConfig?.[componentName]; + + demoList.forEach(demoFile => { + const skip: string[] = option?.skip || []; + const test = skip.some(skipMarkdown => demoFile.includes(skipMarkdown)) ? it.skip : it; + + test(demoFile, () => { + const Demo = require(`../../${demoFile}`).default; // eslint-disable-line global-require, import/no-dynamic-require + expect(() => { + renderToString(); + }).not.toThrow(); + }); + }); + }); + }); +}); diff --git a/components/_util/reactNode.ts b/components/_util/reactNode.ts index 759fd7a6c2..1fc075b619 100644 --- a/components/_util/reactNode.ts +++ b/components/_util/reactNode.ts @@ -6,17 +6,18 @@ export function isFragment(child: React.ReactElement): boolean { return child && child.type === React.Fragment; } -type AnyObject = Record; +type AnyObject = Record; -type RenderProps = undefined | AnyObject | ((originProps: AnyObject) => AnyObject | undefined); +type RenderProps = AnyObject | ((originProps: AnyObject) => AnyObject | void); export function replaceElement( element: React.ReactNode, replacement: React.ReactNode, - props: RenderProps, + props?: RenderProps, ): React.ReactNode { - if (!isValidElement(element)) return replacement; - + if (!isValidElement(element)) { + return replacement; + } return React.cloneElement( element, typeof props === 'function' ? props(element.props || {}) : props, diff --git a/components/affix/__tests__/Affix.test.tsx b/components/affix/__tests__/Affix.test.tsx index 47e4ee4794..b65684f8a6 100644 --- a/components/affix/__tests__/Affix.test.tsx +++ b/components/affix/__tests__/Affix.test.tsx @@ -65,6 +65,11 @@ describe('Affix Render', () => { } as DOMRect, }; + beforeEach(() => { + const entities = getObserverEntities(); + entities.splice(0, entities.length); + }); + beforeAll(() => { domMock.mockImplementation(function fn(this: HTMLElement) { return ( @@ -171,22 +176,20 @@ describe('Affix Render', () => { }); it('instance change', async () => { - const getObserverLength = () => Object.keys(getObserverEntities()).length; - const container = document.createElement('div'); document.body.appendChild(container); let target: HTMLDivElement | null = container; - const originLength = getObserverLength(); const getTarget = () => target; const { rerender } = render({null}); await sleep(100); + expect(getObserverEntities()).toHaveLength(1); + expect(getObserverEntities()[0].target).toBe(container); - expect(getObserverLength()).toBe(originLength + 1); target = null; rerender({null}); - await sleep(100); - expect(getObserverLength()).toBe(originLength); + expect(getObserverEntities()).toHaveLength(1); + expect(getObserverEntities()[0].target).toBe(window); }); }); diff --git a/components/affix/__tests__/__snapshots__/demo-extend.test.ts.snap b/components/affix/__tests__/__snapshots__/demo-extend.test.ts.snap index a77adba253..2edf5200fb 100644 --- a/components/affix/__tests__/__snapshots__/demo-extend.test.ts.snap +++ b/components/affix/__tests__/__snapshots__/demo-extend.test.ts.snap @@ -36,7 +36,7 @@ Array [ exports[`renders ./components/affix/demo/debug.md extend context correctly 1`] = `
Top @@ -46,7 +46,7 @@ exports[`renders ./components/affix/demo/debug.md extend context correctly 1`] = class="" >
`; diff --git a/components/alert/__tests__/__snapshots__/demo.test.ts.snap b/components/alert/__tests__/__snapshots__/demo.test.ts.snap index b3006dc519..64b8500e6d 100644 --- a/components/alert/__tests__/__snapshots__/demo.test.ts.snap +++ b/components/alert/__tests__/__snapshots__/demo.test.ts.snap @@ -214,7 +214,7 @@ Array [ >
`; diff --git a/components/alert/__tests__/__snapshots__/index.test.tsx.snap b/components/alert/__tests__/__snapshots__/index.test.tsx.snap index 0ece9e15eb..70bf6220e3 100644 --- a/components/alert/__tests__/__snapshots__/index.test.tsx.snap +++ b/components/alert/__tests__/__snapshots__/index.test.tsx.snap @@ -1,6 +1,6 @@ // Jest Snapshot v1, https://goo.gl/fbAQLP -exports[`Alert action of Alert custom action 1`] = ` +exports[`Alert custom action 1`] = `
`; -exports[`Alert could accept none react element icon 1`] = ` - -`; - exports[`Alert rtl render component should be rendered correctly in RTL direction 1`] = `
`; - -exports[`Alert support closeIcon 1`] = ` - -`; diff --git a/components/alert/__tests__/demo-extend.test.ts b/components/alert/__tests__/demo-extend.test.ts index 5751215777..f0592bac09 100644 --- a/components/alert/__tests__/demo-extend.test.ts +++ b/components/alert/__tests__/demo-extend.test.ts @@ -1,3 +1,3 @@ import { extendTest } from '../../../tests/shared/demoTest'; -extendTest('alert'); +extendTest('alert', { skip: ['loop-banner.md'] }); diff --git a/components/alert/__tests__/demo.test.ts b/components/alert/__tests__/demo.test.ts index 0810864015..86318266b3 100644 --- a/components/alert/__tests__/demo.test.ts +++ b/components/alert/__tests__/demo.test.ts @@ -1,3 +1,3 @@ import demoTest from '../../../tests/shared/demoTest'; -demoTest('alert'); +demoTest('alert', { skip: ['loop-banner.md'] }); diff --git a/components/alert/__tests__/index.test.tsx b/components/alert/__tests__/index.test.tsx index 8deabf09d6..8cdf5788f5 100644 --- a/components/alert/__tests__/index.test.tsx +++ b/components/alert/__tests__/index.test.tsx @@ -1,8 +1,9 @@ import React from 'react'; +import userEvent from '@testing-library/user-event'; import Alert from '..'; import accessibilityTest from '../../../tests/shared/accessibilityTest'; import rtlTest from '../../../tests/shared/rtlTest'; -import { fireEvent, render, sleep, act } from '../../../tests/utils'; +import { render, act, screen } from '../../../tests/utils'; import Button from '../../button'; import Popconfirm from '../../popconfirm'; import Tooltip from '../../tooltip'; @@ -21,9 +22,9 @@ describe('Alert', () => { jest.useRealTimers(); }); - it('could be closed', () => { + it('should show close button and could be closed', async () => { const onClose = jest.fn(); - const { container } = render( + render( { />, ); - jest.useFakeTimers(); - fireEvent.click(container.querySelector('.ant-alert-close-icon')!); + await userEvent.click(screen.getByRole('button', { name: /close/i })); + act(() => { jest.runAllTimers(); }); - expect(onClose).toHaveBeenCalled(); - jest.useRealTimers(); + + expect(onClose).toHaveBeenCalledTimes(1); }); - describe('action of Alert', () => { - it('custom action', () => { - const { container } = render( - - UNDO - - } - closable - />, - ); - expect(container.firstChild).toMatchSnapshot(); - }); - }); - - it('support closeIcon', () => { + it('custom action', () => { const { container } = render( + UNDO + + } closable - closeIcon={close} - message="Warning Text Warning Text Warning TextW arning Text Warning Text Warning TextWarning Text" - type="warning" />, ); expect(container.firstChild).toMatchSnapshot(); }); - describe('data and aria props', () => { - it('sets data attributes on input', () => { - const { container } = render(); - const input = container.querySelector('.ant-alert')!; - expect(input.getAttribute('data-test')).toBe('test-id'); - expect(input.getAttribute('data-id')).toBe('12345'); - }); - - it('sets aria attributes on input', () => { - const { container } = render(); - const input = container.querySelector('.ant-alert')!; - expect(input.getAttribute('aria-describedby')).toBe('some-label'); - }); - - it('sets role attribute on input', () => { - const { container } = render(); - const input = container.querySelector('.ant-alert')!; - expect(input.getAttribute('role')).toBe('status'); - }); + it('should sets data attributes on alert when pass attributes to props', () => { + render( + , + ); + const alert = screen.getByRole('alert'); + expect(alert).toHaveAttribute('data-test', 'test-id'); + expect(alert).toHaveAttribute('data-id', '12345'); + expect(alert).toHaveAttribute('aria-describedby', 'some-label'); }); - it('ErrorBoundary', () => { + it('sets role attribute on input', () => { + render(); + + expect(screen.getByRole('status')).toBeInTheDocument(); + }); + + it('should show error as ErrorBoundary when children have error', () => { jest.spyOn(console, 'error').mockImplementation(() => undefined); // eslint-disable-next-line no-console expect(console.error).toHaveBeenCalledTimes(0); // @ts-expect-error // eslint-disable-next-line react/jsx-no-undef const ThrowError = () => ; - const { container } = render( + render( , ); - // eslint-disable-next-line jest/no-standalone-expect - expect(container.textContent).toContain('ReferenceError: NotExisted is not defined'); + + expect(screen.getByRole('alert')).toHaveTextContent( + 'ReferenceError: NotExisted is not defined', + ); // eslint-disable-next-line no-console (console.error as any).mockRestore(); }); it('could be used with Tooltip', async () => { - const ref = React.createRef(); - jest.useRealTimers(); - const { container } = render( - + render( + , ); - // wrapper.find('.ant-alert').simulate('mouseenter'); - fireEvent.mouseEnter(container.querySelector('.ant-alert')!); - await sleep(0); - expect(ref.current.getPopupDomNode()).toBeTruthy(); - jest.useFakeTimers(); + + await userEvent.hover(screen.getByRole('alert')); + + expect(screen.getByRole('tooltip')).toBeInTheDocument(); }); it('could be used with Popconfirm', async () => { - const ref = React.createRef(); - jest.useRealTimers(); - const { container } = render( - + render( + , ); - fireEvent.click(container.querySelector('.ant-alert')!); - await sleep(0); - expect(ref.current.getPopupDomNode()).toBeTruthy(); - jest.useFakeTimers(); + await userEvent.click(screen.getByRole('alert')); + + expect(screen.getByRole('tooltip')).toBeInTheDocument(); }); it('could accept none react element icon', () => { - const { container } = render( - , - ); - expect(container.firstChild).toMatchSnapshot(); + render(); + + expect(screen.getByRole('alert')).toHaveTextContent(/success tips/i); + expect(screen.getByRole('alert')).toHaveTextContent(/icon/i); }); it('should not render message div when no message', () => { diff --git a/components/anchor/__tests__/__snapshots__/demo-extend.test.ts.snap b/components/anchor/__tests__/__snapshots__/demo-extend.test.ts.snap index 3d65031817..2f4ff9307d 100644 --- a/components/anchor/__tests__/__snapshots__/demo-extend.test.ts.snap +++ b/components/anchor/__tests__/__snapshots__/demo-extend.test.ts.snap @@ -7,7 +7,7 @@ exports[`renders ./components/anchor/demo/basic.md extend context correctly 1`] >