@mui/internal-test-utils 2.0.15 → 2.0.18-canary.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +11 -3
- package/LICENSE +1 -1
- package/README.md +52 -6
- package/chaiPlugin.d.ts +3 -0
- package/chaiPlugin.js +300 -0
- package/{src/chai.types.ts → chaiTypes.d.ts} +7 -40
- package/chaiTypes.js +5 -0
- package/{build/components.d.ts → components.d.ts} +18 -19
- package/components.js +65 -0
- package/configure.d.ts +9 -0
- package/configure.js +16 -0
- package/createDescribe.d.ts +14 -0
- package/createDescribe.js +33 -0
- package/createRenderer.d.ts +216 -0
- package/createRenderer.js +447 -0
- package/describeConformance.d.ts +196 -0
- package/describeConformance.js +1043 -0
- package/env.d.ts +9 -0
- package/env.js +21 -0
- package/esm/chaiPlugin.d.ts +3 -0
- package/esm/chaiPlugin.js +293 -0
- package/esm/chaiTypes.d.ts +74 -0
- package/esm/chaiTypes.js +3 -0
- package/esm/components.d.ts +35 -0
- package/esm/components.js +57 -0
- package/esm/configure.d.ts +9 -0
- package/esm/configure.js +9 -0
- package/esm/createDescribe.d.ts +14 -0
- package/esm/createDescribe.js +27 -0
- package/esm/createRenderer.d.ts +216 -0
- package/esm/createRenderer.js +396 -0
- package/esm/describeConformance.d.ts +196 -0
- package/esm/describeConformance.js +1029 -0
- package/esm/env.d.ts +9 -0
- package/esm/env.js +13 -0
- package/esm/flushMicrotasks.d.ts +1 -0
- package/esm/flushMicrotasks.js +4 -0
- package/{build → esm}/focusVisible.d.ts +1 -2
- package/{src/focusVisible.ts → esm/focusVisible.js} +10 -9
- package/esm/index.d.ts +10 -0
- package/esm/index.js +18 -0
- package/esm/initMatchers.d.ts +5 -0
- package/esm/initMatchers.js +9 -0
- package/esm/initPlaywrightMatchers.d.ts +24 -0
- package/esm/initPlaywrightMatchers.js +40 -0
- package/esm/package.json +1 -0
- package/esm/setupVitest.d.ts +8 -0
- package/esm/setupVitest.js +94 -0
- package/flushMicrotasks.d.ts +1 -0
- package/flushMicrotasks.js +10 -0
- package/focusVisible.d.ts +7 -0
- package/focusVisible.js +44 -0
- package/index.d.ts +10 -0
- package/index.js +125 -0
- package/initMatchers.d.ts +5 -0
- package/initMatchers.js +29 -0
- package/initPlaywrightMatchers.d.ts +24 -0
- package/initPlaywrightMatchers.js +42 -0
- package/package.json +106 -52
- package/setupVitest.d.ts +8 -0
- package/setupVitest.js +104 -0
- package/build/.tsbuildinfo +0 -1
- package/build/KarmaReporterReactProfiler.d.ts +0 -51
- package/build/KarmaReporterReactProfiler.d.ts.map +0 -1
- package/build/KarmaReporterReactProfiler.js +0 -66
- package/build/KarmaReporterReactProfiler.js.map +0 -1
- package/build/chai.types.d.ts +0 -75
- package/build/chai.types.d.ts.map +0 -1
- package/build/chai.types.js +0 -3
- package/build/chai.types.js.map +0 -1
- package/build/chaiPlugin.d.ts +0 -5
- package/build/chaiPlugin.d.ts.map +0 -1
- package/build/chaiPlugin.js +0 -416
- package/build/chaiPlugin.js.map +0 -1
- package/build/components.d.ts.map +0 -1
- package/build/components.js +0 -88
- package/build/components.js.map +0 -1
- package/build/createDOM.d.ts +0 -3
- package/build/createDOM.d.ts.map +0 -1
- package/build/createDOM.js +0 -60
- package/build/createDOM.js.map +0 -1
- package/build/createDescribe.d.ts +0 -8
- package/build/createDescribe.d.ts.map +0 -1
- package/build/createDescribe.js +0 -22
- package/build/createDescribe.js.map +0 -1
- package/build/createRenderer.d.ts +0 -215
- package/build/createRenderer.d.ts.map +0 -1
- package/build/createRenderer.js +0 -564
- package/build/createRenderer.js.map +0 -1
- package/build/createRenderer.test.d.ts +0 -2
- package/build/createRenderer.test.d.ts.map +0 -1
- package/build/createRenderer.test.js +0 -58
- package/build/createRenderer.test.js.map +0 -1
- package/build/describeConformance.d.ts +0 -201
- package/build/describeConformance.d.ts.map +0 -1
- package/build/describeConformance.js +0 -859
- package/build/describeConformance.js.map +0 -1
- package/build/describeSkipIf.d.ts +0 -4
- package/build/describeSkipIf.d.ts.map +0 -1
- package/build/describeSkipIf.js +0 -10
- package/build/describeSkipIf.js.map +0 -1
- package/build/fireDiscreteEvent.d.ts +0 -7
- package/build/fireDiscreteEvent.d.ts.map +0 -1
- package/build/fireDiscreteEvent.js +0 -77
- package/build/fireDiscreteEvent.js.map +0 -1
- package/build/flushMicrotasks.d.ts +0 -2
- package/build/flushMicrotasks.d.ts.map +0 -1
- package/build/flushMicrotasks.js +0 -8
- package/build/flushMicrotasks.js.map +0 -1
- package/build/focusVisible.d.ts.map +0 -1
- package/build/focusVisible.js +0 -38
- package/build/focusVisible.js.map +0 -1
- package/build/index.d.ts +0 -18
- package/build/index.d.ts.map +0 -1
- package/build/index.js +0 -68
- package/build/index.js.map +0 -1
- package/build/init.d.ts +0 -2
- package/build/init.d.ts.map +0 -1
- package/build/init.js +0 -46
- package/build/init.js.map +0 -1
- package/build/initMatchers.d.ts +0 -2
- package/build/initMatchers.d.ts.map +0 -1
- package/build/initMatchers.js +0 -45
- package/build/initMatchers.js.map +0 -1
- package/build/initMatchers.test.d.ts +0 -2
- package/build/initMatchers.test.d.ts.map +0 -1
- package/build/initMatchers.test.js +0 -101
- package/build/initMatchers.test.js.map +0 -1
- package/build/initPlaywrightMatchers.d.ts +0 -25
- package/build/initPlaywrightMatchers.d.ts.map +0 -1
- package/build/initPlaywrightMatchers.js +0 -73
- package/build/initPlaywrightMatchers.js.map +0 -1
- package/build/mochaHooks.d.ts +0 -24
- package/build/mochaHooks.d.ts.map +0 -1
- package/build/mochaHooks.js +0 -165
- package/build/mochaHooks.js.map +0 -1
- package/build/mochaHooks.test.d.ts +0 -2
- package/build/mochaHooks.test.d.ts.map +0 -1
- package/build/mochaHooks.test.js +0 -128
- package/build/mochaHooks.test.js.map +0 -1
- package/build/reactMajor.d.ts +0 -3
- package/build/reactMajor.d.ts.map +0 -1
- package/build/reactMajor.js +0 -38
- package/build/reactMajor.js.map +0 -1
- package/build/setup.d.ts +0 -2
- package/build/setup.d.ts.map +0 -1
- package/build/setup.js +0 -10
- package/build/setup.js.map +0 -1
- package/build/setupBabel.d.ts +0 -2
- package/build/setupBabel.d.ts.map +0 -1
- package/build/setupBabel.js +0 -5
- package/build/setupBabel.js.map +0 -1
- package/build/setupBabelPlaywright.d.ts +0 -2
- package/build/setupBabelPlaywright.d.ts.map +0 -1
- package/build/setupBabelPlaywright.js +0 -14
- package/build/setupBabelPlaywright.js.map +0 -1
- package/build/setupJSDOM.d.ts +0 -7
- package/build/setupJSDOM.d.ts.map +0 -1
- package/build/setupJSDOM.js +0 -17
- package/build/setupJSDOM.js.map +0 -1
- package/build/setupKarma.d.ts +0 -2
- package/build/setupKarma.d.ts.map +0 -1
- package/build/setupKarma.js +0 -56
- package/build/setupKarma.js.map +0 -1
- package/build/setupVitest.d.ts +0 -2
- package/build/setupVitest.d.ts.map +0 -1
- package/build/setupVitest.js +0 -131
- package/build/setupVitest.js.map +0 -1
- package/src/KarmaReporterReactProfiler.js +0 -82
- package/src/chai-augmentation.d.ts +0 -8
- package/src/chaiPlugin.ts +0 -515
- package/src/components.tsx +0 -61
- package/src/createDOM.d.ts +0 -9
- package/src/createDOM.js +0 -67
- package/src/createDescribe.ts +0 -31
- package/src/createRenderer.test.js +0 -31
- package/src/createRenderer.tsx +0 -808
- package/src/describeConformance.tsx +0 -1257
- package/src/describeSkipIf.tsx +0 -11
- package/src/fireDiscreteEvent.ts +0 -76
- package/src/flushMicrotasks.ts +0 -5
- package/src/index.ts +0 -25
- package/src/init.js +0 -11
- package/src/initMatchers.test.js +0 -124
- package/src/initMatchers.ts +0 -7
- package/src/initPlaywrightMatchers.ts +0 -101
- package/src/mochaHooks.js +0 -200
- package/src/mochaHooks.test.js +0 -116
- package/src/reactMajor.ts +0 -3
- package/src/setup.js +0 -10
- package/src/setupBabel.js +0 -3
- package/src/setupBabelPlaywright.js +0 -13
- package/src/setupJSDOM.js +0 -20
- package/src/setupKarma.js +0 -65
- package/src/setupVitest.ts +0 -117
- package/tsconfig.build.json +0 -16
- package/tsconfig.json +0 -17
package/CHANGELOG.md
CHANGED
package/LICENSE
CHANGED
package/README.md
CHANGED
|
@@ -1,9 +1,55 @@
|
|
|
1
|
-
#
|
|
1
|
+
# MUI Public
|
|
2
2
|
|
|
3
|
-
|
|
4
|
-
|
|
3
|
+
Mono-repository for the MUI organization with code that can be public.
|
|
4
|
+
See https://github.com/mui/mui-private for code that needs to be private.
|
|
5
5
|
|
|
6
|
-
##
|
|
6
|
+
## Documentation
|
|
7
7
|
|
|
8
|
-
|
|
9
|
-
|
|
8
|
+
You can [read the Infra documentation here](./docs/README.md).
|
|
9
|
+
|
|
10
|
+
## Applications
|
|
11
|
+
|
|
12
|
+
### [tools-public.mui.com](https://tools-public.mui.com/)
|
|
13
|
+
|
|
14
|
+
- Folder: `/apps/tools-public/`
|
|
15
|
+
- Hosting: https://dashboard.render.com/web/srv-d08mooq4d50c73fso49g
|
|
16
|
+
- [Docs](./apps/tools-public/#readme)
|
|
17
|
+
|
|
18
|
+
Internal public Toolpad apps that run the operations of MUI, built using https://github.com/mui/toolpad.
|
|
19
|
+
|
|
20
|
+
### [Code infra dashboard](https://frontend-public.mui.com/)
|
|
21
|
+
|
|
22
|
+
- URL: [frontend-public.mui.com](https://frontend-public.mui.com/)
|
|
23
|
+
- Folder: `/apps/code-infra-dashboard/`
|
|
24
|
+
- Hosting: https://app.netlify.com/sites/mui-frontend-public/overview
|
|
25
|
+
- [Docs](./apps/code-infra-dashboard/#readme)
|
|
26
|
+
|
|
27
|
+
## Packages
|
|
28
|
+
|
|
29
|
+
### [docs-infra](./packages/docs-infra/)
|
|
30
|
+
|
|
31
|
+
- Folder: `/packages/docs-infra/`
|
|
32
|
+
- [Docs](./packages/docs-infra/README.md)
|
|
33
|
+
|
|
34
|
+
### [code-infra](./packages/code-infra/)
|
|
35
|
+
|
|
36
|
+
- Folder: `/packages/code-infra/`
|
|
37
|
+
- [Docs](./packages/code-infra/README.md)
|
|
38
|
+
|
|
39
|
+
## Versioning
|
|
40
|
+
|
|
41
|
+
Steps:
|
|
42
|
+
|
|
43
|
+
1. Checkout latest master
|
|
44
|
+
1. Run `pnpm release:prepare`
|
|
45
|
+
1. Run `pnpm release:version`
|
|
46
|
+
1. Open PR with the changes
|
|
47
|
+
|
|
48
|
+
## Publishing
|
|
49
|
+
|
|
50
|
+
Steps:
|
|
51
|
+
|
|
52
|
+
1. Merge versioning PR
|
|
53
|
+
1. Checkout release commit on master
|
|
54
|
+
1. Run `pnpm release:prepare`
|
|
55
|
+
1. Run `pnpm release:publish`
|
package/chaiPlugin.d.ts
ADDED
package/chaiPlugin.js
ADDED
|
@@ -0,0 +1,300 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault").default;
|
|
4
|
+
Object.defineProperty(exports, "__esModule", {
|
|
5
|
+
value: true
|
|
6
|
+
});
|
|
7
|
+
exports.default = void 0;
|
|
8
|
+
var _dom = require("@testing-library/dom");
|
|
9
|
+
var _pure = require("@testing-library/react/pure.js");
|
|
10
|
+
var _domAccessibilityApi = require("dom-accessibility-api");
|
|
11
|
+
var _formatUtil = _interopRequireDefault(require("format-util"));
|
|
12
|
+
var _string = require("es-toolkit/string");
|
|
13
|
+
var _assertionError = require("assertion-error");
|
|
14
|
+
var _env = require("./env");
|
|
15
|
+
// eslint-disable-next-line import/extensions
|
|
16
|
+
|
|
17
|
+
// chai#utils.elToString that looks like stringified elements in testing-library
|
|
18
|
+
function elementToString(element) {
|
|
19
|
+
if (typeof element?.nodeType === 'number') {
|
|
20
|
+
return (0, _pure.prettyDOM)(element, undefined, {
|
|
21
|
+
highlight: true,
|
|
22
|
+
maxDepth: 1
|
|
23
|
+
});
|
|
24
|
+
}
|
|
25
|
+
return String(element);
|
|
26
|
+
}
|
|
27
|
+
const chaiPlugin = (chaiAPI, utils) => {
|
|
28
|
+
const blockElements = new Set(['html', 'address', 'blockquote', 'body', 'dd', 'div', 'dl', 'dt', 'fieldset', 'form', 'frame', 'frameset', 'h1', 'h2', 'h3', 'h4', 'h5', 'h6', 'noframes', 'ol', 'p', 'ul', 'center', 'dir', 'hr', 'menu', 'pre']);
|
|
29
|
+
function pretendVisibleGetComputedStyle(element) {
|
|
30
|
+
// `CSSStyleDeclaration` is not constructable
|
|
31
|
+
// https://stackoverflow.com/a/52732909/3406963
|
|
32
|
+
// this is not equivalent to the declaration from `getComputedStyle`
|
|
33
|
+
// for example `getComputedStyle` would return a readonly declaration
|
|
34
|
+
// let's hope this doesn't get passed around until it's no longer clear where it comes from
|
|
35
|
+
const declaration = document.createElement('span').style;
|
|
36
|
+
|
|
37
|
+
// initial values
|
|
38
|
+
declaration.content = '';
|
|
39
|
+
// technically it's `inline`. We partially apply the default user agent sheet (chrome) here
|
|
40
|
+
// we're only interested in elements that use block
|
|
41
|
+
declaration.display = blockElements.has(element.tagName) ? 'block' : 'inline';
|
|
42
|
+
declaration.visibility = 'visible';
|
|
43
|
+
return declaration;
|
|
44
|
+
}
|
|
45
|
+
|
|
46
|
+
// better diff view for expect(element).to.equal(document.activeElement)
|
|
47
|
+
chaiAPI.Assertion.addMethod('toHaveFocus', function elementIsFocused() {
|
|
48
|
+
const element = utils.flag(this, 'object');
|
|
49
|
+
this.assert(element === document.activeElement, `expected element to have focus`, `expected element to NOT have focus \n${elementToString(element)}`, elementToString(element), elementToString(document.activeElement));
|
|
50
|
+
});
|
|
51
|
+
chaiAPI.Assertion.addMethod('toHaveVirtualFocus', function elementIsVirtuallyFocused() {
|
|
52
|
+
const element = utils.flag(this, 'object');
|
|
53
|
+
const id = element.getAttribute('id');
|
|
54
|
+
const virtuallyFocusedElementId = document.activeElement.getAttribute('aria-activedescendant');
|
|
55
|
+
this.assert(virtuallyFocusedElementId === id, `expected element to be virtually focused\nexpected id #{exp}\n${virtuallyFocusedElementId === null ? `activeElement: ${elementToString(document.activeElement)}` : 'actual id: #{act}'}`, 'expected element to NOT to be virtually focused', id, virtuallyFocusedElementId, virtuallyFocusedElementId !== null);
|
|
56
|
+
});
|
|
57
|
+
chaiAPI.Assertion.addMethod('toBeInaccessible', function elementIsAccessible() {
|
|
58
|
+
const element = utils.flag(this, 'object');
|
|
59
|
+
const inaccessible = (0, _dom.isInaccessible)(element);
|
|
60
|
+
this.assert(inaccessible === true, `expected \n${elementToString(element)} to be inaccessible but it was accessible`, `expected \n${elementToString(element)} to be accessible but it was inaccessible`,
|
|
61
|
+
// Not interested in a diff but the typings require the 4th parameter.
|
|
62
|
+
undefined);
|
|
63
|
+
});
|
|
64
|
+
chaiAPI.Assertion.addMethod('toHaveAccessibleName', function hasAccessibleName(expectedName) {
|
|
65
|
+
const root = utils.flag(this, 'object');
|
|
66
|
+
// make sure it's an Element
|
|
67
|
+
new chaiAPI.Assertion(root.nodeType, `Expected an Element but got '${String(root)}'`).to.equal(1);
|
|
68
|
+
const actualName = (0, _domAccessibilityApi.computeAccessibleName)(root, {
|
|
69
|
+
computedStyleSupportsPseudoElements: !(0, _env.isJsdom)(),
|
|
70
|
+
// in local development we pretend to be visible. full getComputedStyle is
|
|
71
|
+
// expensive and reserved for CI
|
|
72
|
+
getComputedStyle: process.env.CI ? undefined : pretendVisibleGetComputedStyle
|
|
73
|
+
});
|
|
74
|
+
this.assert(actualName === expectedName, `expected \n${elementToString(root)} to have accessible name #{exp} but got #{act} instead.`, `expected \n${elementToString(root)} not to have accessible name #{exp}.`, expectedName, actualName);
|
|
75
|
+
});
|
|
76
|
+
chaiAPI.Assertion.addMethod('toHaveAccessibleDescription', function hasAccessibleDescription(expectedDescription) {
|
|
77
|
+
const root = utils.flag(this, 'object');
|
|
78
|
+
// make sure it's an Element
|
|
79
|
+
new chaiAPI.Assertion(root.nodeType, `Expected an Element but got '${String(root)}'`).to.equal(1);
|
|
80
|
+
const actualDescription = (0, _domAccessibilityApi.computeAccessibleDescription)(root, {
|
|
81
|
+
// in local development we pretend to be visible. full getComputedStyle is
|
|
82
|
+
// expensive and reserved for CI
|
|
83
|
+
getComputedStyle: process.env.CI ? undefined : pretendVisibleGetComputedStyle
|
|
84
|
+
});
|
|
85
|
+
const possibleDescriptionComputationMessage = root.hasAttribute('title') ? ' computeAccessibleDescription can be misleading when a `title` attribute is used. This might be a bug in `dom-accessibility-api`.' : '';
|
|
86
|
+
this.assert(actualDescription === expectedDescription, `expected \n${elementToString(root)} to have accessible description #{exp} but got #{act} instead.${possibleDescriptionComputationMessage}`, `expected \n${elementToString(root)} not to have accessible description #{exp}.${possibleDescriptionComputationMessage}`, expectedDescription, actualDescription);
|
|
87
|
+
});
|
|
88
|
+
|
|
89
|
+
/**
|
|
90
|
+
* Correct name for `to.be.visible`
|
|
91
|
+
*/
|
|
92
|
+
chaiAPI.Assertion.addMethod('toBeVisible', function toBeVisible() {
|
|
93
|
+
// eslint-disable-next-line no-underscore-dangle, @typescript-eslint/no-unused-expressions
|
|
94
|
+
new chaiAPI.Assertion(this._obj).to.be.visible;
|
|
95
|
+
});
|
|
96
|
+
|
|
97
|
+
/**
|
|
98
|
+
* Correct name for `not.to.be.visible`
|
|
99
|
+
*/
|
|
100
|
+
chaiAPI.Assertion.addMethod('toBeHidden', function toBeHidden() {
|
|
101
|
+
// eslint-disable-next-line no-underscore-dangle, @typescript-eslint/no-unused-expressions
|
|
102
|
+
new chaiAPI.Assertion(this._obj).not.to.be.visible;
|
|
103
|
+
});
|
|
104
|
+
function assertMatchingStyles(actualStyleDeclaration, expectedStyleUnnormalized, options) {
|
|
105
|
+
const {
|
|
106
|
+
styleTypeHint
|
|
107
|
+
} = options;
|
|
108
|
+
|
|
109
|
+
// Compare objects using hyphen case.
|
|
110
|
+
// This is closer to actual CSS and required for getPropertyValue anyway.
|
|
111
|
+
const expectedStyle = {};
|
|
112
|
+
Object.keys(expectedStyleUnnormalized).forEach(cssProperty => {
|
|
113
|
+
const hyphenCasedPropertyName = (0, _string.kebabCase)(cssProperty);
|
|
114
|
+
const isVendorPrefixed = /^(moz|ms|o|webkit)-/.test(hyphenCasedPropertyName);
|
|
115
|
+
const propertyName = isVendorPrefixed ? `-${hyphenCasedPropertyName}` : hyphenCasedPropertyName;
|
|
116
|
+
expectedStyle[propertyName] = expectedStyleUnnormalized[cssProperty];
|
|
117
|
+
});
|
|
118
|
+
const shorthandProperties = new Set(['all', 'animation', 'background', 'border', 'border-block-end', 'border-block-start', 'border-bottom', 'border-color', 'border-image', 'border-inline-end', 'border-inline-start', 'border-left', 'border-radius', 'border-right', 'border-style', 'border-top', 'border-width', 'column-rule', 'columns', 'flex', 'flex-flow', 'font', 'gap', 'grid', 'grid-area', 'grid-column', 'grid-row', 'grid-template', 'list-style', 'margin', 'mask', 'offset', 'outline', 'overflow', 'padding', 'place-content', 'place-items', 'place-self', 'scroll-margin', 'scroll-padding', 'text-decoration', 'text-emphasis', 'transition']);
|
|
119
|
+
const usedShorthandProperties = Object.keys(expectedStyle).filter(cssProperty => {
|
|
120
|
+
return shorthandProperties.has(cssProperty);
|
|
121
|
+
});
|
|
122
|
+
if (usedShorthandProperties.length > 0) {
|
|
123
|
+
throw new Error([`Shorthand properties are not supported in ${styleTypeHint} styles matchers since browsers can compute them differently. `, 'Use longhand properties instead for the follow shorthand properties:\n', usedShorthandProperties.map(cssProperty => {
|
|
124
|
+
return `- https://developer.mozilla.org/en-US/docs/Web/CSS/${cssProperty}#constituent_properties`;
|
|
125
|
+
}).join('\n')].join(''));
|
|
126
|
+
}
|
|
127
|
+
const actualStyle = {};
|
|
128
|
+
Object.keys(expectedStyle).forEach(cssProperty => {
|
|
129
|
+
actualStyle[cssProperty] = actualStyleDeclaration.getPropertyValue(cssProperty);
|
|
130
|
+
});
|
|
131
|
+
const jsdomHint = 'Styles in JSDOM e.g. from `test:unit` are often misleading since JSDOM does not implement the Cascade nor actual CSS property value computation. ' + "If results differ between real browsers and JSDOM, skip the test in JSDOM e.g. `it.skipIf(isJsdom())('...`";
|
|
132
|
+
const shorthandHint = 'Browsers can compute shorthand properties differently. Prefer longhand properties e.g. `borderTopColor`, `borderRightColor` etc. instead of `border` or `border-color`.';
|
|
133
|
+
const messageHint = `${jsdomHint}\n${shorthandHint}`;
|
|
134
|
+
this.assert(
|
|
135
|
+
// TODO Fix upstream docs/types
|
|
136
|
+
utils.eql(actualStyle, expectedStyle), `expected #{this} to have ${styleTypeHint} style #{exp} \n\n${messageHint}`, `expected #{this} not to have ${styleTypeHint} style #{exp}${messageHint}`, expectedStyle, actualStyle, true);
|
|
137
|
+
}
|
|
138
|
+
chaiAPI.Assertion.addMethod('toHaveInlineStyle', function toHaveInlineStyle(expectedStyleUnnormalized) {
|
|
139
|
+
const element = utils.flag(this, 'object');
|
|
140
|
+
if (element?.nodeType !== 1) {
|
|
141
|
+
// Same pre-condition for negated and unnegated assertion
|
|
142
|
+
throw new _assertionError.AssertionError(`Expected an Element but got ${String(element)}`);
|
|
143
|
+
}
|
|
144
|
+
assertMatchingStyles.call(this, element.style, expectedStyleUnnormalized, {
|
|
145
|
+
styleTypeHint: 'inline'
|
|
146
|
+
});
|
|
147
|
+
});
|
|
148
|
+
chaiAPI.Assertion.addMethod('toHaveComputedStyle', function toHaveComputedStyle(expectedStyleUnnormalized) {
|
|
149
|
+
const element = utils.flag(this, 'object');
|
|
150
|
+
if (element?.nodeType !== 1) {
|
|
151
|
+
// Same pre-condition for negated and unnegated assertion
|
|
152
|
+
throw new _assertionError.AssertionError(`Expected an Element but got ${String(element)}`);
|
|
153
|
+
}
|
|
154
|
+
const computedStyle = element.ownerDocument.defaultView.getComputedStyle(element);
|
|
155
|
+
assertMatchingStyles.call(this, computedStyle, expectedStyleUnnormalized, {
|
|
156
|
+
styleTypeHint: 'computed'
|
|
157
|
+
});
|
|
158
|
+
});
|
|
159
|
+
chaiAPI.Assertion.addMethod('toThrowMinified', function toThrowMinified(expectedDevMessage) {
|
|
160
|
+
// TODO: Investigate if `as any` can be removed after https://github.com/DefinitelyTyped/DefinitelyTyped/issues/48634 is resolved.
|
|
161
|
+
if (process.env.NODE_ENV !== 'production') {
|
|
162
|
+
this.to.throw(expectedDevMessage);
|
|
163
|
+
} else {
|
|
164
|
+
utils.flag(this, 'message', "Looks like the error was not minified. This can happen if the error code hasn't been generated yet. Run `pnpm extract-error-codes` and try again.");
|
|
165
|
+
// TODO: Investigate if `as any` can be removed after https://github.com/DefinitelyTyped/DefinitelyTyped/issues/48634 is resolved.
|
|
166
|
+
this.to.throw('Minified MUI error', 'helper');
|
|
167
|
+
}
|
|
168
|
+
});
|
|
169
|
+
function addConsoleMatcher(matcherName, methodName) {
|
|
170
|
+
function matcher(expectedMessagesInput = []) {
|
|
171
|
+
// documented pattern to get the actual value of the assertion
|
|
172
|
+
// eslint-disable-next-line no-underscore-dangle
|
|
173
|
+
const callback = this._obj;
|
|
174
|
+
if (process.env.NODE_ENV !== 'production') {
|
|
175
|
+
const expectedMessages = Array.isArray(expectedMessagesInput) ? expectedMessagesInput.slice() : [expectedMessagesInput];
|
|
176
|
+
const unexpectedMessages = [];
|
|
177
|
+
// TODO Remove type once MUI X enables noImplicitAny
|
|
178
|
+
let caughtError = null;
|
|
179
|
+
let result = null;
|
|
180
|
+
this.assert(expectedMessages.length > 0, `Expected to call console.${methodName} but didn't provide messages. ` + `If you don't expect any messages prefer \`expect().not.${matcherName}();\`.`, `Expected no call to console.${methodName} while also expecting messages. ` + "If you want to make sure a certain message isn't logged prefer the positive. " + 'By expecting certain messages you automatically expect that no other messages are logged',
|
|
181
|
+
// Not interested in a diff but the typings require the 4th parameter.
|
|
182
|
+
undefined);
|
|
183
|
+
|
|
184
|
+
// Ignore skipped messages in e.g. `[condition && 'foo']`
|
|
185
|
+
const remainingMessages = expectedMessages.filter(messageOrFalse => {
|
|
186
|
+
return messageOrFalse !== false;
|
|
187
|
+
});
|
|
188
|
+
|
|
189
|
+
// eslint-disable-next-line no-console
|
|
190
|
+
const originalMethod = console[methodName];
|
|
191
|
+
let messagesMatched = 0;
|
|
192
|
+
const consoleMatcher = (format, ...args) => {
|
|
193
|
+
// Ignore legacy root deprecation warnings
|
|
194
|
+
// TODO: Remove once we no longer use legacy roots.
|
|
195
|
+
if (format.includes('Use createRoot instead.') || format.includes('Use hydrateRoot instead.')) {
|
|
196
|
+
return;
|
|
197
|
+
}
|
|
198
|
+
const actualMessage = (0, _formatUtil.default)(format, ...args);
|
|
199
|
+
const expectedMessage = remainingMessages.shift();
|
|
200
|
+
messagesMatched += 1;
|
|
201
|
+
|
|
202
|
+
// TODO Remove type once MUI X enables noImplicitAny
|
|
203
|
+
let message = null;
|
|
204
|
+
if (expectedMessage === undefined) {
|
|
205
|
+
message = `Expected no more error messages but got:\n"${actualMessage}"`;
|
|
206
|
+
} else if (typeof expectedMessage === 'string' && !actualMessage.includes(expectedMessage) || expectedMessage instanceof RegExp && !expectedMessage.test(actualMessage)) {
|
|
207
|
+
message = `Expected #${messagesMatched} "${expectedMessage}" to be included in \n"${actualMessage}"`;
|
|
208
|
+
}
|
|
209
|
+
if (message !== null) {
|
|
210
|
+
const error = new Error(message);
|
|
211
|
+
const {
|
|
212
|
+
stack: fullStack
|
|
213
|
+
} = error;
|
|
214
|
+
const fullStacktrace = fullStack.replace(`Error: ${message}\n`, '').split('\n');
|
|
215
|
+
const usefulStacktrace = fullStacktrace
|
|
216
|
+
//
|
|
217
|
+
// first line points to this frame which is irrelevant for the tester
|
|
218
|
+
.slice(1);
|
|
219
|
+
const usefulStack = `${message}\n${usefulStacktrace.join('\n')}`;
|
|
220
|
+
error.stack = usefulStack;
|
|
221
|
+
unexpectedMessages.push(error);
|
|
222
|
+
}
|
|
223
|
+
};
|
|
224
|
+
// eslint-disable-next-line no-console
|
|
225
|
+
console[methodName] = consoleMatcher;
|
|
226
|
+
try {
|
|
227
|
+
result = callback();
|
|
228
|
+
} catch (error) {
|
|
229
|
+
caughtError = error;
|
|
230
|
+
} finally {
|
|
231
|
+
// unexpected thrown error takes precedence over unexpected console call
|
|
232
|
+
if (caughtError !== null) {
|
|
233
|
+
// not the same pattern as described in the block because we don't rethrow in the catch
|
|
234
|
+
// eslint-disable-next-line no-unsafe-finally
|
|
235
|
+
throw caughtError;
|
|
236
|
+
}
|
|
237
|
+
const formatMessages = messages => {
|
|
238
|
+
const formattedMessages = messages.map(message => {
|
|
239
|
+
if (typeof message === 'string') {
|
|
240
|
+
return `"${message}"`;
|
|
241
|
+
}
|
|
242
|
+
// full Error
|
|
243
|
+
return `${message.stack}`;
|
|
244
|
+
});
|
|
245
|
+
return `\n\n - ${formattedMessages.join('\n\n- ')}`;
|
|
246
|
+
};
|
|
247
|
+
const report = () => {
|
|
248
|
+
const shouldHaveWarned = utils.flag(this, 'negate') !== true;
|
|
249
|
+
|
|
250
|
+
// unreachable from expect().not.toWarnDev(messages)
|
|
251
|
+
if (unexpectedMessages.length > 0) {
|
|
252
|
+
const unexpectedMessageRecordedMessage = `Recorded unexpected console.${methodName} calls: ${formatMessages(unexpectedMessages)}`;
|
|
253
|
+
// chai will duplicate the stack frames from the unexpected calls in their assertion error
|
|
254
|
+
// it's not ideal but the test failure is located the second to last stack frame
|
|
255
|
+
// and the origin of the call is the second stackframe in the stack
|
|
256
|
+
this.assert(
|
|
257
|
+
// force chai to always trigger an assertion error
|
|
258
|
+
!shouldHaveWarned, unexpectedMessageRecordedMessage, unexpectedMessageRecordedMessage,
|
|
259
|
+
// Not interested in a diff but the typings require the 4th parameter.
|
|
260
|
+
undefined);
|
|
261
|
+
}
|
|
262
|
+
if (shouldHaveWarned) {
|
|
263
|
+
this.assert(remainingMessages.length === 0, `Could not match the following console.${methodName} calls. ` + `Make sure previous actions didn't call console.${methodName} by wrapping them in expect(() => {}).not.${matcherName}(): ${formatMessages(remainingMessages)}`, `Impossible state reached in \`expect().${matcherName}()\`. ` + `This is a bug in the matcher.`,
|
|
264
|
+
// Not interested in a diff but the typings require the 4th parameter.
|
|
265
|
+
undefined);
|
|
266
|
+
}
|
|
267
|
+
};
|
|
268
|
+
if (result && typeof result === 'object' && 'then' in result && typeof result.then === 'function') {
|
|
269
|
+
// Handle async callbacks
|
|
270
|
+
result = Promise.resolve(result).then(value => {
|
|
271
|
+
report();
|
|
272
|
+
return value;
|
|
273
|
+
}).finally(() => {
|
|
274
|
+
// eslint-disable-next-line no-console
|
|
275
|
+
console[methodName] = originalMethod;
|
|
276
|
+
});
|
|
277
|
+
} else {
|
|
278
|
+
// eslint-disable-next-line no-console
|
|
279
|
+
console[methodName] = originalMethod;
|
|
280
|
+
report();
|
|
281
|
+
}
|
|
282
|
+
}
|
|
283
|
+
return result;
|
|
284
|
+
}
|
|
285
|
+
|
|
286
|
+
// nothing to do in prod
|
|
287
|
+
// If there are still console calls than our test setup throws.
|
|
288
|
+
return callback();
|
|
289
|
+
}
|
|
290
|
+
chaiAPI.Assertion.addMethod(matcherName, matcher);
|
|
291
|
+
}
|
|
292
|
+
|
|
293
|
+
/**
|
|
294
|
+
* @example expect(() => render()).toWarnDev('single message')
|
|
295
|
+
* @example expect(() => render()).toWarnDev(['first warning', 'then the second'])
|
|
296
|
+
*/
|
|
297
|
+
addConsoleMatcher('toWarnDev', 'warn');
|
|
298
|
+
addConsoleMatcher('toErrorDev', 'error');
|
|
299
|
+
};
|
|
300
|
+
var _default = exports.default = chaiPlugin;
|
|
@@ -1,64 +1,31 @@
|
|
|
1
1
|
export {};
|
|
2
|
-
|
|
3
|
-
// https://stackoverflow.com/a/46755166/3406963
|
|
4
2
|
declare global {
|
|
5
|
-
// eslint-disable-next-line @typescript-eslint/no-namespace
|
|
6
3
|
namespace Chai {
|
|
7
4
|
interface Assertion {
|
|
8
5
|
/**
|
|
9
6
|
* Checks `expectedStyle` is a subset of the elements inline style i.e. `element.style`.
|
|
10
7
|
* @example expect(element).toHaveInlineStyle({ width: '200px' })
|
|
11
8
|
*/
|
|
12
|
-
toHaveInlineStyle(
|
|
13
|
-
expectedStyle: Partial<
|
|
14
|
-
Record<
|
|
15
|
-
Exclude<
|
|
16
|
-
keyof CSSStyleDeclaration,
|
|
17
|
-
| 'getPropertyPriority'
|
|
18
|
-
| 'getPropertyValue'
|
|
19
|
-
| 'item'
|
|
20
|
-
| 'removeProperty'
|
|
21
|
-
| 'setProperty'
|
|
22
|
-
| number
|
|
23
|
-
>,
|
|
24
|
-
string
|
|
25
|
-
>
|
|
26
|
-
>,
|
|
27
|
-
): void;
|
|
9
|
+
toHaveInlineStyle(expectedStyle: Partial<Record<Exclude<keyof CSSStyleDeclaration, 'getPropertyPriority' | 'getPropertyValue' | 'item' | 'removeProperty' | 'setProperty' | number>, string>>): void;
|
|
28
10
|
/**
|
|
29
11
|
* Checks `expectedStyle` is a subset of the elements computed style i.e. `window.getComputedStyle(element)`.
|
|
30
12
|
* @example expect(element).toHaveComputedStyle({ width: '200px' })
|
|
31
13
|
*/
|
|
32
|
-
toHaveComputedStyle(
|
|
33
|
-
expectedStyle: Partial<
|
|
34
|
-
Record<
|
|
35
|
-
Exclude<
|
|
36
|
-
keyof CSSStyleDeclaration,
|
|
37
|
-
| 'getPropertyPriority'
|
|
38
|
-
| 'getPropertyValue'
|
|
39
|
-
| 'item'
|
|
40
|
-
| 'removeProperty'
|
|
41
|
-
| 'setProperty'
|
|
42
|
-
| number
|
|
43
|
-
>,
|
|
44
|
-
string
|
|
45
|
-
>
|
|
46
|
-
>,
|
|
47
|
-
): void;
|
|
14
|
+
toHaveComputedStyle(expectedStyle: Partial<Record<Exclude<keyof CSSStyleDeclaration, 'getPropertyPriority' | 'getPropertyValue' | 'item' | 'removeProperty' | 'setProperty' | number>, string>>): void;
|
|
48
15
|
/**
|
|
49
|
-
* Check if an element's [`visibility`](https://developer.mozilla.org/en-US/docs/Web/CSS/visibility) is not `hidden` or `collapsed`.
|
|
16
|
+
* Check if an element's [`visibility`](https://developer.mozilla.org/en-US/docs/Web/CSS/Reference/Properties/visibility) is not `hidden` or `collapsed`.
|
|
50
17
|
*/
|
|
51
18
|
toBeVisible(): void;
|
|
52
19
|
/**
|
|
53
|
-
* Check if an element's [`visibility`](https://developer.mozilla.org/en-US/docs/Web/CSS/visibility) is `hidden` or `collapsed`.
|
|
20
|
+
* Check if an element's [`visibility`](https://developer.mozilla.org/en-US/docs/Web/CSS/Reference/Properties/visibility) is `hidden` or `collapsed`.
|
|
54
21
|
*/
|
|
55
22
|
toBeHidden(): void;
|
|
56
23
|
/**
|
|
57
24
|
* Checks if the element is inaccessible.
|
|
58
25
|
*
|
|
59
26
|
* Elements are considered inaccessible if they either:
|
|
60
|
-
* - have [`visibility`](https://developer.mozilla.org/en-US/docs/Web/CSS/visibility) `hidden`
|
|
61
|
-
* - have [`display`](https://developer.mozilla.org/en-US/docs/Web/CSS/display) `none`
|
|
27
|
+
* - have [`visibility`](https://developer.mozilla.org/en-US/docs/Web/CSS/Reference/Properties/visibility) `hidden`
|
|
28
|
+
* - have [`display`](https://developer.mozilla.org/en-US/docs/Web/CSS/Reference/Properties/display) `none`
|
|
62
29
|
* - have `aria-hidden` `true` or any of their parents
|
|
63
30
|
*
|
|
64
31
|
* @see [Excluding Elements from the Accessibility Tree](https://www.w3.org/TR/wai-aria-1.2/#tree_exclusion)
|
|
@@ -104,4 +71,4 @@ declare global {
|
|
|
104
71
|
toThrowMinified(message: string | RegExp): void;
|
|
105
72
|
}
|
|
106
73
|
}
|
|
107
|
-
}
|
|
74
|
+
}
|
package/chaiTypes.js
ADDED
|
@@ -6,23 +6,23 @@ import PropTypes from 'prop-types';
|
|
|
6
6
|
* expect(errorRef.current.errors).to.have.length(0);
|
|
7
7
|
*/
|
|
8
8
|
export declare class ErrorBoundary extends React.Component<{
|
|
9
|
-
|
|
9
|
+
children: React.ReactNode;
|
|
10
10
|
}> {
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
11
|
+
static propTypes: {
|
|
12
|
+
children: PropTypes.Validator<NonNullable<PropTypes.ReactNodeLike>>;
|
|
13
|
+
};
|
|
14
|
+
state: {
|
|
15
|
+
error: null;
|
|
16
|
+
};
|
|
17
|
+
/**
|
|
18
|
+
* @public
|
|
19
|
+
*/
|
|
20
|
+
errors: unknown[];
|
|
21
|
+
static getDerivedStateFromError(error: unknown): {
|
|
22
|
+
error: unknown;
|
|
23
|
+
};
|
|
24
|
+
componentDidCatch(error: unknown): void;
|
|
25
|
+
render(): React.ReactNode;
|
|
26
26
|
}
|
|
27
27
|
/**
|
|
28
28
|
* Allows counting how many times the owner of `RenderCounter` rendered or
|
|
@@ -31,6 +31,5 @@ export declare class ErrorBoundary extends React.Component<{
|
|
|
31
31
|
* getRenderCountRef.current() === 2
|
|
32
32
|
*/
|
|
33
33
|
export declare const RenderCounter: React.ForwardRefExoticComponent<{
|
|
34
|
-
|
|
35
|
-
} & React.RefAttributes<() => number>>;
|
|
36
|
-
//# sourceMappingURL=components.d.ts.map
|
|
34
|
+
children: React.ReactNode;
|
|
35
|
+
} & React.RefAttributes<() => number>>;
|
package/components.js
ADDED
|
@@ -0,0 +1,65 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault").default;
|
|
4
|
+
var _interopRequireWildcard = require("@babel/runtime/helpers/interopRequireWildcard").default;
|
|
5
|
+
Object.defineProperty(exports, "__esModule", {
|
|
6
|
+
value: true
|
|
7
|
+
});
|
|
8
|
+
exports.RenderCounter = exports.ErrorBoundary = void 0;
|
|
9
|
+
var React = _interopRequireWildcard(require("react"));
|
|
10
|
+
var _propTypes = _interopRequireDefault(require("prop-types"));
|
|
11
|
+
var _jsxRuntime = require("react/jsx-runtime");
|
|
12
|
+
/**
|
|
13
|
+
* A basic error boundary that can be used to assert thrown errors in render.
|
|
14
|
+
* @example <ErrorBoundary ref={errorRef}><MyComponent /></ErrorBoundary>;
|
|
15
|
+
* expect(errorRef.current.errors).to.have.length(0);
|
|
16
|
+
*/
|
|
17
|
+
class ErrorBoundary extends React.Component {
|
|
18
|
+
state = {
|
|
19
|
+
error: null
|
|
20
|
+
};
|
|
21
|
+
|
|
22
|
+
/**
|
|
23
|
+
* @public
|
|
24
|
+
*/
|
|
25
|
+
errors = [];
|
|
26
|
+
static getDerivedStateFromError(error) {
|
|
27
|
+
return {
|
|
28
|
+
error
|
|
29
|
+
};
|
|
30
|
+
}
|
|
31
|
+
componentDidCatch(error) {
|
|
32
|
+
this.errors.push(error);
|
|
33
|
+
}
|
|
34
|
+
render() {
|
|
35
|
+
if (this.state.error) {
|
|
36
|
+
return null;
|
|
37
|
+
}
|
|
38
|
+
return this.props.children;
|
|
39
|
+
}
|
|
40
|
+
}
|
|
41
|
+
|
|
42
|
+
/**
|
|
43
|
+
* Allows counting how many times the owner of `RenderCounter` rendered or
|
|
44
|
+
* a component within the RenderCounter tree "commits" an update.
|
|
45
|
+
* @example <RenderCounter ref={getRenderCountRef}>...</RenderCounter>
|
|
46
|
+
* getRenderCountRef.current() === 2
|
|
47
|
+
*/
|
|
48
|
+
exports.ErrorBoundary = ErrorBoundary;
|
|
49
|
+
process.env.NODE_ENV !== "production" ? ErrorBoundary.propTypes = {
|
|
50
|
+
children: _propTypes.default.node.isRequired
|
|
51
|
+
} : void 0;
|
|
52
|
+
const RenderCounter = exports.RenderCounter = /*#__PURE__*/React.forwardRef(function RenderCounter({
|
|
53
|
+
children
|
|
54
|
+
}, ref) {
|
|
55
|
+
const getRenderCountRef = React.useRef(0);
|
|
56
|
+
React.useImperativeHandle(ref, () => () => getRenderCountRef.current);
|
|
57
|
+
return /*#__PURE__*/(0, _jsxRuntime.jsx)(React.Profiler, {
|
|
58
|
+
id: "render-counter",
|
|
59
|
+
onRender: () => {
|
|
60
|
+
getRenderCountRef.current += 1;
|
|
61
|
+
},
|
|
62
|
+
children: children
|
|
63
|
+
});
|
|
64
|
+
});
|
|
65
|
+
if (process.env.NODE_ENV !== "production") RenderCounter.displayName = "RenderCounter";
|
package/configure.d.ts
ADDED
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
export interface Configuration {
|
|
2
|
+
/**
|
|
3
|
+
* The emotion wrapper is optional.
|
|
4
|
+
* If your repository uses emotion, install `@emotion/react` and `@emotion/cache` and set this to true.
|
|
5
|
+
*/
|
|
6
|
+
emotion: boolean;
|
|
7
|
+
}
|
|
8
|
+
export declare const config: Configuration;
|
|
9
|
+
export declare function configure(newConfig?: Partial<Configuration>): void;
|
package/configure.js
ADDED
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, "__esModule", {
|
|
4
|
+
value: true
|
|
5
|
+
});
|
|
6
|
+
exports.config = void 0;
|
|
7
|
+
exports.configure = configure;
|
|
8
|
+
const defaultConfig = {
|
|
9
|
+
emotion: false
|
|
10
|
+
};
|
|
11
|
+
const config = exports.config = {
|
|
12
|
+
...defaultConfig
|
|
13
|
+
};
|
|
14
|
+
function configure(newConfig = {}) {
|
|
15
|
+
Object.assign(config, newConfig);
|
|
16
|
+
}
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
export type MUIDescribe<P extends any[]> = {
|
|
2
|
+
(...args: P): void;
|
|
3
|
+
skip: (...args: P) => void;
|
|
4
|
+
only: (...args: P) => void;
|
|
5
|
+
};
|
|
6
|
+
/**
|
|
7
|
+
* Create a custom describe function with chainable skip and only methods.
|
|
8
|
+
* It is used to group conformance tests but still make the focusable/skippable.
|
|
9
|
+
*
|
|
10
|
+
* @param message - The message to display for the describe block.
|
|
11
|
+
* @param callback - The callback function containing the tests.
|
|
12
|
+
* @returns A custom describe function with skip and only methods.
|
|
13
|
+
*/
|
|
14
|
+
export default function createDescribe<P extends any[]>(message: string, callback: (...args: P) => void): MUIDescribe<P>;
|