ant-design/tests/setupAfterEnv.ts
lijianan db0344c85f
test: migrate part of ConfigProvider tests (#37142)
* test: migrate part of ConfigProvider tests

* test: migrate part of ConfigProvider tests

* test: update snap

* test: update snap

* test: migrate part of ConfigProvider tests

* fix: commented error case

* chore: update snapshot name

* test: csp test case

* test: revert test case

* test: Update snapshot

* test: Update ser logic

* test: more cov

* test: cascader snapshit

* test: update match

* test: more detact

* test: more handler

* chore: Update snapshot

* test: Table test case

Co-authored-by: 二货机器人 <smith3816@gmail.com>
2022-08-22 22:54:38 +08:00

44 lines
1.0 KiB
TypeScript

import { toHaveNoViolations } from 'jest-axe';
import '@testing-library/jest-dom';
import format, { plugins } from 'pretty-format';
/**
* React 17 & 18 will have different behavior in some special cases:
*
* React 17:
*
* ```html
* <span> Hello World </span>
* ```
*
* React 18:
*
* ```html
* <span> Hello World </span>
* ```
*
* These diff is nothing important in front end but will break in snapshot diff.
*/
expect.addSnapshotSerializer({
test: element =>
typeof HTMLElement !== 'undefined' &&
(element instanceof HTMLElement ||
element instanceof DocumentFragment ||
element instanceof HTMLCollection ||
(Array.isArray(element) && element[0] instanceof HTMLElement)),
print: element => {
const htmlContent = format(element, {
plugins: [plugins.DOMCollection, plugins.DOMElement],
});
const filtered = htmlContent
.split(/[\n\r]+/)
.filter(line => line.trim())
.join('\n');
return filtered;
},
});
expect.extend(toHaveNoViolations);