@mui/internal-test-utils 2.0.15 → 2.0.16

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.
Files changed (212) hide show
  1. package/{src/chai.types.ts → chai.types.d.ts} +7 -40
  2. package/chai.types.js +5 -0
  3. package/chaiPlugin.d.ts +4 -0
  4. package/chaiPlugin.js +287 -0
  5. package/{build/components.d.ts → components.d.ts} +18 -19
  6. package/components.js +64 -0
  7. package/createDOM.d.ts +2 -0
  8. package/{src/createDOM.js → createDOM.js} +17 -35
  9. package/createDescribe.d.ts +7 -0
  10. package/createDescribe.js +26 -0
  11. package/createRenderer.d.ts +214 -0
  12. package/createRenderer.js +428 -0
  13. package/createRenderer.test.d.ts +1 -0
  14. package/describeConformance.d.ts +200 -0
  15. package/describeConformance.js +1038 -0
  16. package/env.d.ts +1 -0
  17. package/env.js +11 -0
  18. package/esm/chai.types.d.ts +74 -0
  19. package/esm/chai.types.js +3 -0
  20. package/esm/chaiPlugin.d.ts +4 -0
  21. package/esm/chaiPlugin.js +281 -0
  22. package/esm/components.d.ts +35 -0
  23. package/esm/components.js +56 -0
  24. package/esm/createDOM.d.ts +2 -0
  25. package/esm/createDOM.js +47 -0
  26. package/esm/createDescribe.d.ts +7 -0
  27. package/esm/createDescribe.js +19 -0
  28. package/esm/createRenderer.d.ts +214 -0
  29. package/esm/createRenderer.js +390 -0
  30. package/esm/createRenderer.test.d.ts +1 -0
  31. package/esm/describeConformance.d.ts +200 -0
  32. package/esm/describeConformance.js +1024 -0
  33. package/esm/env.d.ts +1 -0
  34. package/esm/env.js +5 -0
  35. package/{build → esm}/fireDiscreteEvent.d.ts +1 -2
  36. package/{src/fireDiscreteEvent.ts → esm/fireDiscreteEvent.js} +10 -18
  37. package/esm/flushMicrotasks.d.ts +1 -0
  38. package/{src/flushMicrotasks.ts → esm/flushMicrotasks.js} +2 -3
  39. package/{build → esm}/focusVisible.d.ts +1 -2
  40. package/{src/focusVisible.ts → esm/focusVisible.js} +10 -9
  41. package/esm/index.d.ts +18 -0
  42. package/esm/index.js +27 -0
  43. package/esm/init.d.ts +1 -0
  44. package/{src → esm}/init.js +4 -2
  45. package/esm/initMatchers.d.ts +1 -0
  46. package/esm/initMatchers.js +6 -0
  47. package/esm/initMatchers.test.d.ts +1 -0
  48. package/esm/initPlaywrightMatchers.d.ts +24 -0
  49. package/esm/initPlaywrightMatchers.js +40 -0
  50. package/esm/package.json +1 -0
  51. package/esm/reactMajor.d.ts +2 -0
  52. package/esm/reactMajor.js +2 -0
  53. package/esm/setup.d.ts +1 -0
  54. package/{src → esm}/setup.js +2 -4
  55. package/esm/setupVitest.d.ts +1 -0
  56. package/esm/setupVitest.js +28 -0
  57. package/esm/setupVitestBrowser.d.ts +1 -0
  58. package/esm/setupVitestBrowser.js +30 -0
  59. package/fireDiscreteEvent.d.ts +6 -0
  60. package/fireDiscreteEvent.js +79 -0
  61. package/flushMicrotasks.d.ts +1 -0
  62. package/flushMicrotasks.js +10 -0
  63. package/focusVisible.d.ts +7 -0
  64. package/focusVisible.js +44 -0
  65. package/index.d.ts +18 -0
  66. package/index.js +139 -0
  67. package/init.d.ts +1 -0
  68. package/init.js +15 -0
  69. package/initMatchers.d.ts +1 -0
  70. package/initMatchers.js +10 -0
  71. package/initMatchers.test.d.ts +1 -0
  72. package/initPlaywrightMatchers.d.ts +24 -0
  73. package/initPlaywrightMatchers.js +42 -0
  74. package/package.json +89 -46
  75. package/reactMajor.d.ts +2 -0
  76. package/reactMajor.js +9 -0
  77. package/setup.d.ts +1 -0
  78. package/setup.js +10 -0
  79. package/setupVitest.d.ts +1 -0
  80. package/setupVitest.js +32 -0
  81. package/setupVitestBrowser.d.ts +1 -0
  82. package/setupVitestBrowser.js +34 -0
  83. package/build/.tsbuildinfo +0 -1
  84. package/build/KarmaReporterReactProfiler.d.ts +0 -51
  85. package/build/KarmaReporterReactProfiler.d.ts.map +0 -1
  86. package/build/KarmaReporterReactProfiler.js +0 -66
  87. package/build/KarmaReporterReactProfiler.js.map +0 -1
  88. package/build/chai.types.d.ts +0 -75
  89. package/build/chai.types.d.ts.map +0 -1
  90. package/build/chai.types.js +0 -3
  91. package/build/chai.types.js.map +0 -1
  92. package/build/chaiPlugin.d.ts +0 -5
  93. package/build/chaiPlugin.d.ts.map +0 -1
  94. package/build/chaiPlugin.js +0 -416
  95. package/build/chaiPlugin.js.map +0 -1
  96. package/build/components.d.ts.map +0 -1
  97. package/build/components.js +0 -88
  98. package/build/components.js.map +0 -1
  99. package/build/createDOM.d.ts +0 -3
  100. package/build/createDOM.d.ts.map +0 -1
  101. package/build/createDOM.js +0 -60
  102. package/build/createDOM.js.map +0 -1
  103. package/build/createDescribe.d.ts +0 -8
  104. package/build/createDescribe.d.ts.map +0 -1
  105. package/build/createDescribe.js +0 -22
  106. package/build/createDescribe.js.map +0 -1
  107. package/build/createRenderer.d.ts +0 -215
  108. package/build/createRenderer.d.ts.map +0 -1
  109. package/build/createRenderer.js +0 -564
  110. package/build/createRenderer.js.map +0 -1
  111. package/build/createRenderer.test.d.ts +0 -2
  112. package/build/createRenderer.test.d.ts.map +0 -1
  113. package/build/createRenderer.test.js +0 -58
  114. package/build/createRenderer.test.js.map +0 -1
  115. package/build/describeConformance.d.ts +0 -201
  116. package/build/describeConformance.d.ts.map +0 -1
  117. package/build/describeConformance.js +0 -859
  118. package/build/describeConformance.js.map +0 -1
  119. package/build/describeSkipIf.d.ts +0 -4
  120. package/build/describeSkipIf.d.ts.map +0 -1
  121. package/build/describeSkipIf.js +0 -10
  122. package/build/describeSkipIf.js.map +0 -1
  123. package/build/fireDiscreteEvent.d.ts.map +0 -1
  124. package/build/fireDiscreteEvent.js +0 -77
  125. package/build/fireDiscreteEvent.js.map +0 -1
  126. package/build/flushMicrotasks.d.ts +0 -2
  127. package/build/flushMicrotasks.d.ts.map +0 -1
  128. package/build/flushMicrotasks.js +0 -8
  129. package/build/flushMicrotasks.js.map +0 -1
  130. package/build/focusVisible.d.ts.map +0 -1
  131. package/build/focusVisible.js +0 -38
  132. package/build/focusVisible.js.map +0 -1
  133. package/build/index.d.ts +0 -18
  134. package/build/index.d.ts.map +0 -1
  135. package/build/index.js +0 -68
  136. package/build/index.js.map +0 -1
  137. package/build/init.d.ts +0 -2
  138. package/build/init.d.ts.map +0 -1
  139. package/build/init.js +0 -46
  140. package/build/init.js.map +0 -1
  141. package/build/initMatchers.d.ts +0 -2
  142. package/build/initMatchers.d.ts.map +0 -1
  143. package/build/initMatchers.js +0 -45
  144. package/build/initMatchers.js.map +0 -1
  145. package/build/initMatchers.test.d.ts +0 -2
  146. package/build/initMatchers.test.d.ts.map +0 -1
  147. package/build/initMatchers.test.js +0 -101
  148. package/build/initMatchers.test.js.map +0 -1
  149. package/build/initPlaywrightMatchers.d.ts +0 -25
  150. package/build/initPlaywrightMatchers.d.ts.map +0 -1
  151. package/build/initPlaywrightMatchers.js +0 -73
  152. package/build/initPlaywrightMatchers.js.map +0 -1
  153. package/build/mochaHooks.d.ts +0 -24
  154. package/build/mochaHooks.d.ts.map +0 -1
  155. package/build/mochaHooks.js +0 -165
  156. package/build/mochaHooks.js.map +0 -1
  157. package/build/mochaHooks.test.d.ts +0 -2
  158. package/build/mochaHooks.test.d.ts.map +0 -1
  159. package/build/mochaHooks.test.js +0 -128
  160. package/build/mochaHooks.test.js.map +0 -1
  161. package/build/reactMajor.d.ts +0 -3
  162. package/build/reactMajor.d.ts.map +0 -1
  163. package/build/reactMajor.js +0 -38
  164. package/build/reactMajor.js.map +0 -1
  165. package/build/setup.d.ts +0 -2
  166. package/build/setup.d.ts.map +0 -1
  167. package/build/setup.js +0 -10
  168. package/build/setup.js.map +0 -1
  169. package/build/setupBabel.d.ts +0 -2
  170. package/build/setupBabel.d.ts.map +0 -1
  171. package/build/setupBabel.js +0 -5
  172. package/build/setupBabel.js.map +0 -1
  173. package/build/setupBabelPlaywright.d.ts +0 -2
  174. package/build/setupBabelPlaywright.d.ts.map +0 -1
  175. package/build/setupBabelPlaywright.js +0 -14
  176. package/build/setupBabelPlaywright.js.map +0 -1
  177. package/build/setupJSDOM.d.ts +0 -7
  178. package/build/setupJSDOM.d.ts.map +0 -1
  179. package/build/setupJSDOM.js +0 -17
  180. package/build/setupJSDOM.js.map +0 -1
  181. package/build/setupKarma.d.ts +0 -2
  182. package/build/setupKarma.d.ts.map +0 -1
  183. package/build/setupKarma.js +0 -56
  184. package/build/setupKarma.js.map +0 -1
  185. package/build/setupVitest.d.ts +0 -2
  186. package/build/setupVitest.d.ts.map +0 -1
  187. package/build/setupVitest.js +0 -131
  188. package/build/setupVitest.js.map +0 -1
  189. package/src/KarmaReporterReactProfiler.js +0 -82
  190. package/src/chai-augmentation.d.ts +0 -8
  191. package/src/chaiPlugin.ts +0 -515
  192. package/src/components.tsx +0 -61
  193. package/src/createDOM.d.ts +0 -9
  194. package/src/createDescribe.ts +0 -31
  195. package/src/createRenderer.test.js +0 -31
  196. package/src/createRenderer.tsx +0 -808
  197. package/src/describeConformance.tsx +0 -1257
  198. package/src/describeSkipIf.tsx +0 -11
  199. package/src/index.ts +0 -25
  200. package/src/initMatchers.test.js +0 -124
  201. package/src/initMatchers.ts +0 -7
  202. package/src/initPlaywrightMatchers.ts +0 -101
  203. package/src/mochaHooks.js +0 -200
  204. package/src/mochaHooks.test.js +0 -116
  205. package/src/reactMajor.ts +0 -3
  206. package/src/setupBabel.js +0 -3
  207. package/src/setupBabelPlaywright.js +0 -13
  208. package/src/setupJSDOM.js +0 -20
  209. package/src/setupKarma.js +0 -65
  210. package/src/setupVitest.ts +0 -117
  211. package/tsconfig.build.json +0 -16
  212. package/tsconfig.json +0 -17
@@ -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/chai.types.js ADDED
@@ -0,0 +1,5 @@
1
+ "use strict";
2
+
3
+ Object.defineProperty(exports, "__esModule", {
4
+ value: true
5
+ });
@@ -0,0 +1,4 @@
1
+ import * as chai from 'chai';
2
+ import "./chai.types.js";
3
+ declare const chaiPlugin: Parameters<typeof chai.use>[0];
4
+ export default chaiPlugin;
package/chaiPlugin.js ADDED
@@ -0,0 +1,287 @@
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");
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
+ require("./chai.types");
15
+ var _env = require("./env");
16
+ // chai#utils.elToString that looks like stringified elements in testing-library
17
+ function elementToString(element) {
18
+ if (typeof element?.nodeType === 'number') {
19
+ return (0, _pure.prettyDOM)(element, undefined, {
20
+ highlight: true,
21
+ maxDepth: 1
22
+ });
23
+ }
24
+ return String(element);
25
+ }
26
+ const chaiPlugin = (chaiAPI, utils) => {
27
+ 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']);
28
+ function pretendVisibleGetComputedStyle(element) {
29
+ // `CSSStyleDeclaration` is not constructable
30
+ // https://stackoverflow.com/a/52732909/3406963
31
+ // this is not equivalent to the declaration from `getComputedStyle`
32
+ // for example `getComputedStyle` would return a readonly declaration
33
+ // let's hope this doesn't get passed around until it's no longer clear where it comes from
34
+ const declaration = document.createElement('span').style;
35
+
36
+ // initial values
37
+ declaration.content = '';
38
+ // technically it's `inline`. We partially apply the default user agent sheet (chrome) here
39
+ // we're only interested in elements that use block
40
+ declaration.display = blockElements.has(element.tagName) ? 'block' : 'inline';
41
+ declaration.visibility = 'visible';
42
+ return declaration;
43
+ }
44
+
45
+ // better diff view for expect(element).to.equal(document.activeElement)
46
+ chaiAPI.Assertion.addMethod('toHaveFocus', function elementIsFocused() {
47
+ const element = utils.flag(this, 'object');
48
+ this.assert(element === document.activeElement, `expected element to have focus`, `expected element to NOT have focus \n${elementToString(element)}`, elementToString(element), elementToString(document.activeElement));
49
+ });
50
+ chaiAPI.Assertion.addMethod('toHaveVirtualFocus', function elementIsVirtuallyFocused() {
51
+ const element = utils.flag(this, 'object');
52
+ const id = element.getAttribute('id');
53
+ const virtuallyFocusedElementId = document.activeElement.getAttribute('aria-activedescendant');
54
+ 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);
55
+ });
56
+ chaiAPI.Assertion.addMethod('toBeInaccessible', function elementIsAccessible() {
57
+ const element = utils.flag(this, 'object');
58
+ const inaccessible = (0, _dom.isInaccessible)(element);
59
+ 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`,
60
+ // Not interested in a diff but the typings require the 4th parameter.
61
+ undefined);
62
+ });
63
+ chaiAPI.Assertion.addMethod('toHaveAccessibleName', function hasAccessibleName(expectedName) {
64
+ const root = utils.flag(this, 'object');
65
+ // make sure it's an Element
66
+ new chaiAPI.Assertion(root.nodeType, `Expected an Element but got '${String(root)}'`).to.equal(1);
67
+ const actualName = (0, _domAccessibilityApi.computeAccessibleName)(root, {
68
+ computedStyleSupportsPseudoElements: !(0, _env.isJsdom)(),
69
+ // in local development we pretend to be visible. full getComputedStyle is
70
+ // expensive and reserved for CI
71
+ getComputedStyle: process.env.CI ? undefined : pretendVisibleGetComputedStyle
72
+ });
73
+ 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);
74
+ });
75
+ chaiAPI.Assertion.addMethod('toHaveAccessibleDescription', function hasAccessibleDescription(expectedDescription) {
76
+ const root = utils.flag(this, 'object');
77
+ // make sure it's an Element
78
+ new chaiAPI.Assertion(root.nodeType, `Expected an Element but got '${String(root)}'`).to.equal(1);
79
+ const actualDescription = (0, _domAccessibilityApi.computeAccessibleDescription)(root, {
80
+ // in local development we pretend to be visible. full getComputedStyle is
81
+ // expensive and reserved for CI
82
+ getComputedStyle: process.env.CI ? undefined : pretendVisibleGetComputedStyle
83
+ });
84
+ const possibleDescriptionComputationMessage = root.hasAttribute('title') ? ' computeAccessibleDescription can be misleading when a `title` attribute is used. This might be a bug in `dom-accessibility-api`.' : '';
85
+ 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);
86
+ });
87
+
88
+ /**
89
+ * Correct name for `to.be.visible`
90
+ */
91
+ chaiAPI.Assertion.addMethod('toBeVisible', function toBeVisible() {
92
+ // eslint-disable-next-line no-underscore-dangle, @typescript-eslint/no-unused-expressions
93
+ new chaiAPI.Assertion(this._obj).to.be.visible;
94
+ });
95
+
96
+ /**
97
+ * Correct name for `not.to.be.visible`
98
+ */
99
+ chaiAPI.Assertion.addMethod('toBeHidden', function toBeHidden() {
100
+ // eslint-disable-next-line no-underscore-dangle, @typescript-eslint/no-unused-expressions
101
+ new chaiAPI.Assertion(this._obj).not.to.be.visible;
102
+ });
103
+ function assertMatchingStyles(actualStyleDeclaration, expectedStyleUnnormalized, options) {
104
+ const {
105
+ styleTypeHint
106
+ } = options;
107
+
108
+ // Compare objects using hyphen case.
109
+ // This is closer to actual CSS and required for getPropertyValue anyway.
110
+ const expectedStyle = {};
111
+ Object.keys(expectedStyleUnnormalized).forEach(cssProperty => {
112
+ const hyphenCasedPropertyName = (0, _string.kebabCase)(cssProperty);
113
+ const isVendorPrefixed = /^(moz|ms|o|webkit)-/.test(hyphenCasedPropertyName);
114
+ const propertyName = isVendorPrefixed ? `-${hyphenCasedPropertyName}` : hyphenCasedPropertyName;
115
+ expectedStyle[propertyName] = expectedStyleUnnormalized[cssProperty];
116
+ });
117
+ 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']);
118
+ const usedShorthandProperties = Object.keys(expectedStyle).filter(cssProperty => {
119
+ return shorthandProperties.has(cssProperty);
120
+ });
121
+ if (usedShorthandProperties.length > 0) {
122
+ 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 => {
123
+ return `- https://developer.mozilla.org/en-US/docs/Web/CSS/${cssProperty}#constituent_properties`;
124
+ }).join('\n')].join(''));
125
+ }
126
+ const actualStyle = {};
127
+ Object.keys(expectedStyle).forEach(cssProperty => {
128
+ actualStyle[cssProperty] = actualStyleDeclaration.getPropertyValue(cssProperty);
129
+ });
130
+ 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())('...`";
131
+ const shorthandHint = 'Browsers can compute shorthand properties differently. Prefer longhand properties e.g. `borderTopColor`, `borderRightColor` etc. instead of `border` or `border-color`.';
132
+ const messageHint = `${jsdomHint}\n${shorthandHint}`;
133
+ this.assert(
134
+ // TODO Fix upstream docs/types
135
+ 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);
136
+ }
137
+ chaiAPI.Assertion.addMethod('toHaveInlineStyle', function toHaveInlineStyle(expectedStyleUnnormalized) {
138
+ const element = utils.flag(this, 'object');
139
+ if (element?.nodeType !== 1) {
140
+ // Same pre-condition for negated and unnegated assertion
141
+ throw new _assertionError.AssertionError(`Expected an Element but got ${String(element)}`);
142
+ }
143
+ assertMatchingStyles.call(this, element.style, expectedStyleUnnormalized, {
144
+ styleTypeHint: 'inline'
145
+ });
146
+ });
147
+ chaiAPI.Assertion.addMethod('toHaveComputedStyle', function toHaveComputedStyle(expectedStyleUnnormalized) {
148
+ const element = utils.flag(this, 'object');
149
+ if (element?.nodeType !== 1) {
150
+ // Same pre-condition for negated and unnegated assertion
151
+ throw new _assertionError.AssertionError(`Expected an Element but got ${String(element)}`);
152
+ }
153
+ const computedStyle = element.ownerDocument.defaultView.getComputedStyle(element);
154
+ assertMatchingStyles.call(this, computedStyle, expectedStyleUnnormalized, {
155
+ styleTypeHint: 'computed'
156
+ });
157
+ });
158
+ chaiAPI.Assertion.addMethod('toThrowMinified', function toThrowMinified(expectedDevMessage) {
159
+ // TODO: Investigate if `as any` can be removed after https://github.com/DefinitelyTyped/DefinitelyTyped/issues/48634 is resolved.
160
+ if (process.env.NODE_ENV !== 'production') {
161
+ this.to.throw(expectedDevMessage);
162
+ } else {
163
+ 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.");
164
+ // TODO: Investigate if `as any` can be removed after https://github.com/DefinitelyTyped/DefinitelyTyped/issues/48634 is resolved.
165
+ this.to.throw('Minified MUI error', 'helper');
166
+ }
167
+ });
168
+ function addConsoleMatcher(matcherName, methodName) {
169
+ /**
170
+ * @param {string[]} expectedMessages
171
+ */
172
+ function matcher(expectedMessagesInput = []) {
173
+ // documented pattern to get the actual value of the assertion
174
+ // eslint-disable-next-line no-underscore-dangle
175
+ const callback = this._obj;
176
+ if (process.env.NODE_ENV !== 'production') {
177
+ const expectedMessages = typeof expectedMessagesInput === 'string' ? [expectedMessagesInput] : expectedMessagesInput.slice();
178
+ const unexpectedMessages = [];
179
+ // TODO Remove type once MUI X enables noImplicitAny
180
+ let caughtError = null;
181
+ 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.` + 'Expected no call to console.error but provided 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',
182
+ // Not interested in a diff but the typings require the 4th parameter.
183
+ undefined);
184
+
185
+ // Ignore skipped messages in e.g. `[condition && 'foo']`
186
+ const remainingMessages = expectedMessages.filter(messageOrFalse => {
187
+ return messageOrFalse !== false;
188
+ });
189
+
190
+ // eslint-disable-next-line no-console
191
+ const originalMethod = console[methodName];
192
+ let messagesMatched = 0;
193
+ const consoleMatcher = (format, ...args) => {
194
+ // Ignore legacy root deprecation warnings
195
+ // TODO: Remove once we no longer use legacy roots.
196
+ if (format.includes('Use createRoot instead.') || format.includes('Use hydrateRoot instead.')) {
197
+ return;
198
+ }
199
+ const actualMessage = (0, _formatUtil.default)(format, ...args);
200
+ const expectedMessage = remainingMessages.shift();
201
+ messagesMatched += 1;
202
+
203
+ // TODO Remove type once MUI X enables noImplicitAny
204
+ let message = null;
205
+ if (expectedMessage === undefined) {
206
+ message = `Expected no more error messages but got:\n"${actualMessage}"`;
207
+ } else if (!actualMessage.includes(expectedMessage)) {
208
+ message = `Expected #${messagesMatched} "${expectedMessage}" to be included in \n"${actualMessage}"`;
209
+ }
210
+ if (message !== null) {
211
+ const error = new Error(message);
212
+ const {
213
+ stack: fullStack
214
+ } = error;
215
+ const fullStacktrace = fullStack.replace(`Error: ${message}\n`, '').split('\n');
216
+ const usefulStacktrace = fullStacktrace
217
+ //
218
+ // first line points to this frame which is irrelevant for the tester
219
+ .slice(1);
220
+ const usefulStack = `${message}\n${usefulStacktrace.join('\n')}`;
221
+ error.stack = usefulStack;
222
+ unexpectedMessages.push(error);
223
+ }
224
+ };
225
+ // eslint-disable-next-line no-console
226
+ console[methodName] = consoleMatcher;
227
+ try {
228
+ callback();
229
+ } catch (error) {
230
+ caughtError = error;
231
+ } finally {
232
+ // eslint-disable-next-line no-console
233
+ console[methodName] = originalMethod;
234
+
235
+ // unexpected thrown error takes precedence over unexpected console call
236
+ if (caughtError !== null) {
237
+ // not the same pattern as described in the block because we don't rethrow in the catch
238
+ // eslint-disable-next-line no-unsafe-finally
239
+ throw caughtError;
240
+ }
241
+ const formatMessages = messages => {
242
+ const formattedMessages = messages.map(message => {
243
+ if (typeof message === 'string') {
244
+ return `"${message}"`;
245
+ }
246
+ // full Error
247
+ return `${message.stack}`;
248
+ });
249
+ return `\n\n - ${formattedMessages.join('\n\n- ')}`;
250
+ };
251
+ const shouldHaveWarned = utils.flag(this, 'negate') !== true;
252
+
253
+ // unreachable from expect().not.toWarnDev(messages)
254
+ if (unexpectedMessages.length > 0) {
255
+ const unexpectedMessageRecordedMessage = `Recorded unexpected console.${methodName} calls: ${formatMessages(unexpectedMessages)}`;
256
+ // chai will duplicate the stack frames from the unexpected calls in their assertion error
257
+ // it's not ideal but the test failure is located the second to last stack frame
258
+ // and the origin of the call is the second stackframe in the stack
259
+ this.assert(
260
+ // force chai to always trigger an assertion error
261
+ !shouldHaveWarned, unexpectedMessageRecordedMessage, unexpectedMessageRecordedMessage,
262
+ // Not interested in a diff but the typings require the 4th parameter.
263
+ undefined);
264
+ }
265
+ if (shouldHaveWarned) {
266
+ 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.`,
267
+ // Not interested in a diff but the typings require the 4th parameter.
268
+ undefined);
269
+ }
270
+ }
271
+ } else {
272
+ // nothing to do in prod
273
+ // If there are still console calls than our test setup throws.
274
+ callback();
275
+ }
276
+ }
277
+ chaiAPI.Assertion.addMethod(matcherName, matcher);
278
+ }
279
+
280
+ /**
281
+ * @example expect(() => render()).toWarnDev('single message')
282
+ * @example expect(() => render()).toWarnDev(['first warning', 'then the second'])
283
+ */
284
+ addConsoleMatcher('toWarnDev', 'warn');
285
+ addConsoleMatcher('toErrorDev', 'error');
286
+ };
287
+ var _default = exports.default = chaiPlugin;
@@ -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
- children: React.ReactNode;
9
+ children: React.ReactNode;
10
10
  }> {
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;
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
- children: React.ReactNode;
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,64 @@
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
+ });
package/createDOM.d.ts ADDED
@@ -0,0 +1,2 @@
1
+ export = createDOM;
2
+ declare function createDOM(): void;
@@ -1,29 +1,21 @@
1
- const { JSDOM } = require('jsdom');
1
+ "use strict";
2
+
3
+ const {
4
+ JSDOM
5
+ } = require('jsdom');
2
6
 
3
7
  // We can use jsdom-global at some point if maintaining these lists is a burden.
4
8
  const whitelist = [
5
- // used by React's experimental cache API
6
- // Always including it to reduce churn when switching between React builds
7
- 'AbortController',
8
- // required for fake getComputedStyle
9
- 'CSSStyleDeclaration',
10
- 'Element',
11
- 'Event',
12
- 'TouchEvent',
13
- 'Image',
14
- 'HTMLElement',
15
- 'HTMLInputElement',
16
- 'Node',
17
- 'Performance',
18
- 'document',
19
- 'DocumentFragment',
20
- ];
9
+ // used by React's experimental cache API
10
+ // Always including it to reduce churn when switching between React builds
11
+ 'AbortController',
12
+ // required for fake getComputedStyle
13
+ 'CSSStyleDeclaration', 'Element', 'Event', 'TouchEvent', 'Image', 'HTMLElement', 'HTMLInputElement', 'Node', 'Performance', 'document', 'DocumentFragment'];
21
14
  const blacklist = ['sessionStorage', 'localStorage'];
22
-
23
15
  function createDOM() {
24
16
  const dom = new JSDOM('', {
25
17
  pretendToBeVisual: true,
26
- url: 'http://localhost',
18
+ url: 'http://localhost'
27
19
  });
28
20
  globalThis.window = dom.window;
29
21
  // Not yet supported: https://github.com/jsdom/jsdom/issues/2152
@@ -31,37 +23,27 @@ function createDOM() {
31
23
  constructor(instance) {
32
24
  this.instance = instance;
33
25
  }
34
-
35
26
  get identifier() {
36
27
  return this.instance.identifier;
37
28
  }
38
-
39
29
  get pageX() {
40
30
  return this.instance.pageX;
41
31
  }
42
-
43
32
  get pageY() {
44
33
  return this.instance.pageY;
45
34
  }
46
-
47
35
  get clientX() {
48
36
  return this.instance.clientX;
49
37
  }
50
-
51
38
  get clientY() {
52
39
  return this.instance.clientY;
53
40
  }
54
41
  }
55
42
  globalThis.window.Touch = Touch;
56
-
57
- Object.keys(dom.window)
58
- .filter((key) => !blacklist.includes(key))
59
- .concat(whitelist)
60
- .forEach((key) => {
61
- if (typeof globalThis[key] === 'undefined') {
62
- globalThis[key] = dom.window[key];
63
- }
64
- });
43
+ Object.keys(dom.window).filter(key => !blacklist.includes(key)).concat(whitelist).forEach(key => {
44
+ if (typeof globalThis[key] === 'undefined') {
45
+ globalThis[key] = dom.window[key];
46
+ }
47
+ });
65
48
  }
66
-
67
- module.exports = createDOM;
49
+ module.exports = createDOM;
@@ -0,0 +1,7 @@
1
+ type MUIDescribe<P extends any[]> = {
2
+ (...args: P): void;
3
+ skip: (...args: P) => void;
4
+ only: (...args: P) => void;
5
+ };
6
+ declare const _default: <P extends any[]>(message: string, callback: (...args: P) => void) => MUIDescribe<P>;
7
+ export default _default;
@@ -0,0 +1,26 @@
1
+ "use strict";
2
+
3
+ Object.defineProperty(exports, "__esModule", {
4
+ value: true
5
+ });
6
+ exports.default = void 0;
7
+ var _vitest = require("vitest");
8
+ var _default = (message, callback) => {
9
+ const muiDescribe = (...args) => {
10
+ (0, _vitest.describe)(message, () => {
11
+ callback(...args);
12
+ });
13
+ };
14
+ muiDescribe.skip = (...args) => {
15
+ _vitest.describe.skip(message, () => {
16
+ callback(...args);
17
+ });
18
+ };
19
+ muiDescribe.only = (...args) => {
20
+ _vitest.describe.only(message, () => {
21
+ callback(...args);
22
+ });
23
+ };
24
+ return muiDescribe;
25
+ };
26
+ exports.default = _default;