@mui/internal-test-utils 1.0.19 → 1.0.20

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 (55) hide show
  1. package/build/.tsbuildinfo +1 -1
  2. package/build/chai.types.d.ts +75 -0
  3. package/build/chai.types.d.ts.map +1 -0
  4. package/build/chai.types.js +3 -0
  5. package/build/chai.types.js.map +1 -0
  6. package/build/chaiPlugin.d.ts +5 -0
  7. package/build/chaiPlugin.d.ts.map +1 -0
  8. package/build/chaiPlugin.js +406 -0
  9. package/build/chaiPlugin.js.map +1 -0
  10. package/build/createDOM.js +4 -4
  11. package/build/createDOM.js.map +1 -1
  12. package/build/createRenderer.d.ts +37 -62
  13. package/build/createRenderer.d.ts.map +1 -1
  14. package/build/createRenderer.js +85 -40
  15. package/build/createRenderer.js.map +1 -1
  16. package/build/describeConformance.d.ts.map +1 -1
  17. package/build/describeConformance.js +28 -14
  18. package/build/describeConformance.js.map +1 -1
  19. package/build/describeSkipIf.d.ts +3 -0
  20. package/build/describeSkipIf.d.ts.map +1 -0
  21. package/build/describeSkipIf.js +10 -0
  22. package/build/describeSkipIf.js.map +1 -0
  23. package/build/index.d.ts +1 -0
  24. package/build/index.d.ts.map +1 -1
  25. package/build/index.js +3 -1
  26. package/build/index.js.map +1 -1
  27. package/build/initMatchers.d.ts +1 -74
  28. package/build/initMatchers.d.ts.map +1 -1
  29. package/build/initMatchers.js +4 -400
  30. package/build/initMatchers.js.map +1 -1
  31. package/build/initMatchers.test.js +4 -6
  32. package/build/initMatchers.test.js.map +1 -1
  33. package/build/mochaHooks.test.js +5 -1
  34. package/build/mochaHooks.test.js.map +1 -1
  35. package/build/setupJSDOM.js +2 -2
  36. package/build/setupJSDOM.js.map +1 -1
  37. package/build/setupVitest.d.ts +2 -0
  38. package/build/setupVitest.d.ts.map +1 -0
  39. package/build/setupVitest.js +121 -0
  40. package/build/setupVitest.js.map +1 -0
  41. package/package.json +6 -4
  42. package/src/chai.types.ts +106 -0
  43. package/src/chaiPlugin.ts +512 -0
  44. package/src/createDOM.js +4 -4
  45. package/src/createRenderer.tsx +106 -51
  46. package/src/describeConformance.tsx +28 -16
  47. package/src/describeSkipIf.tsx +9 -0
  48. package/src/index.ts +1 -0
  49. package/src/initMatchers.test.js +4 -6
  50. package/src/initMatchers.ts +4 -615
  51. package/src/mochaHooks.test.js +2 -1
  52. package/src/setupJSDOM.js +2 -2
  53. package/src/setupVitest.ts +117 -0
  54. package/tsconfig.json +5 -2
  55. package/tsconfig.tsbuildinfo +0 -1
@@ -0,0 +1,75 @@
1
+ export {};
2
+ declare global {
3
+ namespace Chai {
4
+ interface Assertion {
5
+ /**
6
+ * Checks `expectedStyle` is a subset of the elements inline style i.e. `element.style`.
7
+ * @example expect(element).toHaveInlineStyle({ width: '200px' })
8
+ */
9
+ toHaveInlineStyle(expectedStyle: Partial<Record<Exclude<keyof CSSStyleDeclaration, 'getPropertyPriority' | 'getPropertyValue' | 'item' | 'removeProperty' | 'setProperty' | number>, string>>): void;
10
+ /**
11
+ * Checks `expectedStyle` is a subset of the elements computed style i.e. `window.getComputedStyle(element)`.
12
+ * @example expect(element).toHaveComputedStyle({ width: '200px' })
13
+ */
14
+ toHaveComputedStyle(expectedStyle: Partial<Record<Exclude<keyof CSSStyleDeclaration, 'getPropertyPriority' | 'getPropertyValue' | 'item' | 'removeProperty' | 'setProperty' | number>, string>>): void;
15
+ /**
16
+ * Check if an element's [`visibility`](https://developer.mozilla.org/en-US/docs/Web/CSS/visibility) is not `hidden` or `collapsed`.
17
+ */
18
+ toBeVisible(): void;
19
+ /**
20
+ * Check if an element's [`visibility`](https://developer.mozilla.org/en-US/docs/Web/CSS/visibility) is `hidden` or `collapsed`.
21
+ */
22
+ toBeHidden(): void;
23
+ /**
24
+ * Checks if the element is inaccessible.
25
+ *
26
+ * Elements are considered inaccessible if they either:
27
+ * - have [`visibility`](https://developer.mozilla.org/en-US/docs/Web/CSS/visibility) `hidden`
28
+ * - have [`display`](https://developer.mozilla.org/en-US/docs/Web/CSS/display) `none`
29
+ * - have `aria-hidden` `true` or any of their parents
30
+ *
31
+ * @see [Excluding Elements from the Accessibility Tree](https://www.w3.org/TR/wai-aria-1.2/#tree_exclusion)
32
+ */
33
+ toBeInaccessible(): void;
34
+ toHaveAccessibleDescription(description: string): void;
35
+ /**
36
+ * Checks if the accessible name computation (according to `accname` spec)
37
+ * matches the expectation.
38
+ *
39
+ * @see https://www.w3.org/TR/accname-1.2/
40
+ * @param name
41
+ */
42
+ toHaveAccessibleName(name: string): void;
43
+ /**
44
+ * Checks if the element is actually focused i.e. `document.activeElement` is equal to the actual element.
45
+ */
46
+ toHaveFocus(): void;
47
+ /**
48
+ * Checks if the element is the active-descendant of the active element.
49
+ */
50
+ toHaveVirtualFocus(): void;
51
+ /**
52
+ * Matches calls to `console.warn` in the asserted callback.
53
+ *
54
+ * @example expect(() => render()).not.toWarnDev()
55
+ * @example expect(() => render()).toWarnDev('single message')
56
+ * @example expect(() => render()).toWarnDev(['first warning', 'then the second'])
57
+ */
58
+ toWarnDev(messages?: string | readonly (string | boolean)[]): void;
59
+ /**
60
+ * Matches calls to `console.error` in the asserted callback.
61
+ *
62
+ * @example expect(() => render()).not.toErrorDev()
63
+ * @example expect(() => render()).toErrorDev('single message')
64
+ * @example expect(() => render()).toErrorDev(['first warning', 'then the second'])
65
+ */
66
+ toErrorDev(messages?: string | readonly (string | boolean)[]): void;
67
+ /**
68
+ * Asserts that the given callback throws an error matching the given message in development (process.env.NODE_ENV !== 'production').
69
+ * In production it expects a minified error.
70
+ */
71
+ toThrowMinified(message: string): void;
72
+ }
73
+ }
74
+ }
75
+ //# sourceMappingURL=chai.types.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"chai.types.d.ts","sourceRoot":"","sources":["../src/chai.types.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,CAAC;AAGV,OAAO,CAAC,MAAM,CAAC;IACb,UAAU,IAAI,CAAC;QACb,UAAU,SAAS;YACjB;;;eAGG;YACH,iBAAiB,CACf,aAAa,EAAE,OAAO,CACpB,MAAM,CACJ,OAAO,CACL,MAAM,mBAAmB,EACvB,qBAAqB,GACrB,kBAAkB,GAClB,MAAM,GACN,gBAAgB,GAChB,aAAa,GACb,MAAM,CACT,EACD,MAAM,CACP,CACF,GACA,IAAI,CAAC;YACR;;;eAGG;YACH,mBAAmB,CACjB,aAAa,EAAE,OAAO,CACpB,MAAM,CACJ,OAAO,CACL,MAAM,mBAAmB,EACvB,qBAAqB,GACrB,kBAAkB,GAClB,MAAM,GACN,gBAAgB,GAChB,aAAa,GACb,MAAM,CACT,EACD,MAAM,CACP,CACF,GACA,IAAI,CAAC;YACR;;eAEG;YACH,WAAW,IAAI,IAAI,CAAC;YACpB;;eAEG;YACH,UAAU,IAAI,IAAI,CAAC;YACnB;;;;;;;;;eASG;YACH,gBAAgB,IAAI,IAAI,CAAC;YACzB,2BAA2B,CAAC,WAAW,EAAE,MAAM,GAAG,IAAI,CAAC;YACvD;;;;;;eAMG;YACH,oBAAoB,CAAC,IAAI,EAAE,MAAM,GAAG,IAAI,CAAC;YACzC;;eAEG;YACH,WAAW,IAAI,IAAI,CAAC;YACpB;;eAEG;YACH,kBAAkB,IAAI,IAAI,CAAC;YAC3B;;;;;;eAMG;YACH,SAAS,CAAC,QAAQ,CAAC,EAAE,MAAM,GAAG,SAAS,CAAC,MAAM,GAAG,OAAO,CAAC,EAAE,GAAG,IAAI,CAAC;YACnE;;;;;;eAMG;YACH,UAAU,CAAC,QAAQ,CAAC,EAAE,MAAM,GAAG,SAAS,CAAC,MAAM,GAAG,OAAO,CAAC,EAAE,GAAG,IAAI,CAAC;YACpE;;;eAGG;YACH,eAAe,CAAC,OAAO,EAAE,MAAM,GAAG,IAAI,CAAC;SACxC;KACF;CACF"}
@@ -0,0 +1,3 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ //# sourceMappingURL=chai.types.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"chai.types.js","sourceRoot":"","sources":["../src/chai.types.ts"],"names":[],"mappings":""}
@@ -0,0 +1,5 @@
1
+ import chai from 'chai';
2
+ import './chai.types';
3
+ declare const chaiPlugin: Parameters<(typeof chai)['use']>[0];
4
+ export default chaiPlugin;
5
+ //# sourceMappingURL=chaiPlugin.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"chaiPlugin.d.ts","sourceRoot":"","sources":["../src/chaiPlugin.ts"],"names":[],"mappings":"AAEA,OAAO,IAAwB,MAAM,MAAM,CAAC;AAI5C,OAAO,cAAc,CAAC;AAgBtB,QAAA,MAAM,UAAU,EAAE,UAAU,CAAC,CAAC,OAAO,IAAI,CAAC,CAAC,KAAK,CAAC,CAAC,CAAC,CAAC,CAuenD,CAAC;AAEF,eAAe,UAAU,CAAC"}
@@ -0,0 +1,406 @@
1
+ "use strict";
2
+ var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
3
+ if (k2 === undefined) k2 = k;
4
+ var desc = Object.getOwnPropertyDescriptor(m, k);
5
+ if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
6
+ desc = { enumerable: true, get: function() { return m[k]; } };
7
+ }
8
+ Object.defineProperty(o, k2, desc);
9
+ }) : (function(o, m, k, k2) {
10
+ if (k2 === undefined) k2 = k;
11
+ o[k2] = m[k];
12
+ }));
13
+ var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
14
+ Object.defineProperty(o, "default", { enumerable: true, value: v });
15
+ }) : function(o, v) {
16
+ o["default"] = v;
17
+ });
18
+ var __importStar = (this && this.__importStar) || function (mod) {
19
+ if (mod && mod.__esModule) return mod;
20
+ var result = {};
21
+ if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
22
+ __setModuleDefault(result, mod);
23
+ return result;
24
+ };
25
+ var __importDefault = (this && this.__importDefault) || function (mod) {
26
+ return (mod && mod.__esModule) ? mod : { "default": mod };
27
+ };
28
+ Object.defineProperty(exports, "__esModule", { value: true });
29
+ const dom_1 = require("@testing-library/dom");
30
+ const pure_1 = require("@testing-library/react/pure");
31
+ const chai_1 = __importStar(require("chai"));
32
+ const dom_accessibility_api_1 = require("dom-accessibility-api");
33
+ const format_util_1 = __importDefault(require("format-util"));
34
+ const lodash_1 = __importDefault(require("lodash"));
35
+ require("./chai.types");
36
+ const isKarma = Boolean(process.env.KARMA);
37
+ function isInJSDOM() {
38
+ return /jsdom/.test(window.navigator.userAgent);
39
+ }
40
+ // chai#utils.elToString that looks like stringified elements in testing-library
41
+ function elementToString(element) {
42
+ if (typeof element?.nodeType === 'number') {
43
+ return (0, pure_1.prettyDOM)(element, undefined, { highlight: !isKarma, maxDepth: 1 });
44
+ }
45
+ return String(element);
46
+ }
47
+ const chaiPlugin = (chaiAPI, utils) => {
48
+ const blockElements = new Set([
49
+ 'html',
50
+ 'address',
51
+ 'blockquote',
52
+ 'body',
53
+ 'dd',
54
+ 'div',
55
+ 'dl',
56
+ 'dt',
57
+ 'fieldset',
58
+ 'form',
59
+ 'frame',
60
+ 'frameset',
61
+ 'h1',
62
+ 'h2',
63
+ 'h3',
64
+ 'h4',
65
+ 'h5',
66
+ 'h6',
67
+ 'noframes',
68
+ 'ol',
69
+ 'p',
70
+ 'ul',
71
+ 'center',
72
+ 'dir',
73
+ 'hr',
74
+ 'menu',
75
+ 'pre',
76
+ ]);
77
+ function pretendVisibleGetComputedStyle(element) {
78
+ // `CSSStyleDeclaration` is not constructable
79
+ // https://stackoverflow.com/a/52732909/3406963
80
+ // this is not equivalent to the declaration from `getComputedStyle`
81
+ // for example `getComputedStyle` would return a readonly declaration
82
+ // let's hope this doesn't get passed around until it's no longer clear where it comes from
83
+ const declaration = document.createElement('span').style;
84
+ // initial values
85
+ declaration.content = '';
86
+ // technically it's `inline`. We partially apply the default user agent sheet (chrome) here
87
+ // we're only interested in elements that use block
88
+ declaration.display = blockElements.has(element.tagName) ? 'block' : 'inline';
89
+ declaration.visibility = 'visible';
90
+ return declaration;
91
+ }
92
+ // better diff view for expect(element).to.equal(document.activeElement)
93
+ chaiAPI.Assertion.addMethod('toHaveFocus', function elementIsFocused() {
94
+ const element = utils.flag(this, 'object');
95
+ this.assert(element === document.activeElement,
96
+ // karma does not show the diff like mocha does
97
+ `expected element to have focus${isKarma ? '\nexpected #{exp}\nactual: #{act}' : ''}`, `expected element to NOT have focus \n${elementToString(element)}`, elementToString(element), elementToString(document.activeElement));
98
+ });
99
+ chaiAPI.Assertion.addMethod('toHaveVirtualFocus', function elementIsVirtuallyFocused() {
100
+ const element = utils.flag(this, 'object');
101
+ const id = element.getAttribute('id');
102
+ const virtuallyFocusedElementId = document.activeElement.getAttribute('aria-activedescendant');
103
+ this.assert(virtuallyFocusedElementId === id, `expected element to be virtually focused\nexpected id #{exp}\n${virtuallyFocusedElementId === null
104
+ ? `activeElement: ${elementToString(document.activeElement)}`
105
+ : 'actual id: #{act}'}`, 'expected element to NOT to be virtually focused', id, virtuallyFocusedElementId, virtuallyFocusedElementId !== null);
106
+ });
107
+ chaiAPI.Assertion.addMethod('toBeInaccessible', function elementIsAccessible() {
108
+ const element = utils.flag(this, 'object');
109
+ const inaccessible = (0, dom_1.isInaccessible)(element);
110
+ 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`,
111
+ // Not interested in a diff but the typings require the 4th parameter.
112
+ undefined);
113
+ });
114
+ chaiAPI.Assertion.addMethod('toHaveAccessibleName', function hasAccessibleName(expectedName) {
115
+ const root = utils.flag(this, 'object');
116
+ // make sure it's an Element
117
+ new chai_1.default.Assertion(root.nodeType, `Expected an Element but got '${String(root)}'`).to.equal(1);
118
+ const actualName = (0, dom_accessibility_api_1.computeAccessibleName)(root, {
119
+ computedStyleSupportsPseudoElements: !isInJSDOM(),
120
+ // in local development we pretend to be visible. full getComputedStyle is
121
+ // expensive and reserved for CI
122
+ getComputedStyle: process.env.CI ? undefined : pretendVisibleGetComputedStyle,
123
+ });
124
+ 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);
125
+ });
126
+ chaiAPI.Assertion.addMethod('toHaveAccessibleDescription', function hasAccessibleDescription(expectedDescription) {
127
+ const root = utils.flag(this, 'object');
128
+ // make sure it's an Element
129
+ new chai_1.default.Assertion(root.nodeType, `Expected an Element but got '${String(root)}'`).to.equal(1);
130
+ const actualDescription = (0, dom_accessibility_api_1.computeAccessibleDescription)(root, {
131
+ // in local development we pretend to be visible. full getComputedStyle is
132
+ // expensive and reserved for CI
133
+ getComputedStyle: process.env.CI ? undefined : pretendVisibleGetComputedStyle,
134
+ });
135
+ const possibleDescriptionComputationMessage = root.hasAttribute('title')
136
+ ? ' computeAccessibleDescription can be misleading when a `title` attribute is used. This might be a bug in `dom-accessibility-api`.'
137
+ : '';
138
+ 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);
139
+ });
140
+ /**
141
+ * Correct name for `to.be.visible`
142
+ */
143
+ chaiAPI.Assertion.addMethod('toBeVisible', function toBeVisible() {
144
+ // eslint-disable-next-line no-underscore-dangle, @typescript-eslint/no-unused-expressions
145
+ new chaiAPI.Assertion(this._obj).to.be.visible;
146
+ });
147
+ /**
148
+ * Correct name for `not.to.be.visible`
149
+ */
150
+ chaiAPI.Assertion.addMethod('toBeHidden', function toBeHidden() {
151
+ // eslint-disable-next-line no-underscore-dangle, @typescript-eslint/no-unused-expressions
152
+ new chaiAPI.Assertion(this._obj).not.to.be.visible;
153
+ });
154
+ function assertMatchingStyles(actualStyleDeclaration, expectedStyleUnnormalized, options) {
155
+ const { styleTypeHint } = options;
156
+ // Compare objects using hyphen case.
157
+ // This is closer to actual CSS and required for getPropertyValue anyway.
158
+ const expectedStyle = {};
159
+ Object.keys(expectedStyleUnnormalized).forEach((cssProperty) => {
160
+ const hyphenCasedPropertyName = lodash_1.default.kebabCase(cssProperty);
161
+ const isVendorPrefixed = /^(moz|ms|o|webkit)-/.test(hyphenCasedPropertyName);
162
+ const propertyName = isVendorPrefixed
163
+ ? `-${hyphenCasedPropertyName}`
164
+ : hyphenCasedPropertyName;
165
+ expectedStyle[propertyName] = expectedStyleUnnormalized[cssProperty];
166
+ });
167
+ const shorthandProperties = new Set([
168
+ 'all',
169
+ 'animation',
170
+ 'background',
171
+ 'border',
172
+ 'border-block-end',
173
+ 'border-block-start',
174
+ 'border-bottom',
175
+ 'border-color',
176
+ 'border-image',
177
+ 'border-inline-end',
178
+ 'border-inline-start',
179
+ 'border-left',
180
+ 'border-radius',
181
+ 'border-right',
182
+ 'border-style',
183
+ 'border-top',
184
+ 'border-width',
185
+ 'column-rule',
186
+ 'columns',
187
+ 'flex',
188
+ 'flex-flow',
189
+ 'font',
190
+ 'gap',
191
+ 'grid',
192
+ 'grid-area',
193
+ 'grid-column',
194
+ 'grid-row',
195
+ 'grid-template',
196
+ 'list-style',
197
+ 'margin',
198
+ 'mask',
199
+ 'offset',
200
+ 'outline',
201
+ 'overflow',
202
+ 'padding',
203
+ 'place-content',
204
+ 'place-items',
205
+ 'place-self',
206
+ 'scroll-margin',
207
+ 'scroll-padding',
208
+ 'text-decoration',
209
+ 'text-emphasis',
210
+ 'transition',
211
+ ]);
212
+ const usedShorthandProperties = Object.keys(expectedStyle).filter((cssProperty) => {
213
+ return shorthandProperties.has(cssProperty);
214
+ });
215
+ if (usedShorthandProperties.length > 0) {
216
+ throw new Error([
217
+ `Shorthand properties are not supported in ${styleTypeHint} styles matchers since browsers can compute them differently. `,
218
+ 'Use longhand properties instead for the follow shorthand properties:\n',
219
+ usedShorthandProperties
220
+ .map((cssProperty) => {
221
+ return `- https://developer.mozilla.org/en-US/docs/Web/CSS/${cssProperty}#constituent_properties`;
222
+ })
223
+ .join('\n'),
224
+ ].join(''));
225
+ }
226
+ const actualStyle = {};
227
+ Object.keys(expectedStyle).forEach((cssProperty) => {
228
+ actualStyle[cssProperty] = actualStyleDeclaration.getPropertyValue(cssProperty);
229
+ });
230
+ 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. ' +
231
+ 'If results differ between real browsers and JSDOM, skip the test in JSDOM e.g. `if (/jsdom/.test(window.navigator.userAgent)) this.skip();`';
232
+ const shorthandHint = 'Browsers can compute shorthand properties differently. Prefer longhand properties e.g. `borderTopColor`, `borderRightColor` etc. instead of `border` or `border-color`.';
233
+ const messageHint = `${jsdomHint}\n${shorthandHint}`;
234
+ if (isKarma) {
235
+ // `#{exp}` and `#{act}` placeholders escape the newlines
236
+ const expected = JSON.stringify(expectedStyle, null, 2);
237
+ const actual = JSON.stringify(actualStyle, null, 2);
238
+ // karma's `dots` reporter does not support diffs
239
+ this.assert(
240
+ // TODO Fix upstream docs/types
241
+ utils.eql(actualStyle, expectedStyle), `expected ${styleTypeHint} style of #{this} did not match\nExpected:\n${expected}\nActual:\n${actual}\n\n\n${messageHint}`, `expected #{this} to not have ${styleTypeHint} style\n${expected}\n\n\n${messageHint}`, expectedStyle, actualStyle);
242
+ }
243
+ else {
244
+ this.assert(
245
+ // TODO Fix upstream docs/types
246
+ 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);
247
+ }
248
+ }
249
+ chaiAPI.Assertion.addMethod('toHaveInlineStyle', function toHaveInlineStyle(expectedStyleUnnormalized) {
250
+ const element = utils.flag(this, 'object');
251
+ if (element?.nodeType !== 1) {
252
+ // Same pre-condition for negated and unnegated assertion
253
+ throw new chai_1.AssertionError(`Expected an Element but got ${String(element)}`);
254
+ }
255
+ assertMatchingStyles.call(this, element.style, expectedStyleUnnormalized, {
256
+ styleTypeHint: 'inline',
257
+ });
258
+ });
259
+ chaiAPI.Assertion.addMethod('toHaveComputedStyle', function toHaveComputedStyle(expectedStyleUnnormalized) {
260
+ const element = utils.flag(this, 'object');
261
+ if (element?.nodeType !== 1) {
262
+ // Same pre-condition for negated and unnegated assertion
263
+ throw new chai_1.AssertionError(`Expected an Element but got ${String(element)}`);
264
+ }
265
+ const computedStyle = element.ownerDocument.defaultView.getComputedStyle(element);
266
+ assertMatchingStyles.call(this, computedStyle, expectedStyleUnnormalized, {
267
+ styleTypeHint: 'computed',
268
+ });
269
+ });
270
+ chaiAPI.Assertion.addMethod('toThrowMinified', function toThrowMinified(expectedDevMessage) {
271
+ // TODO: Investigate if `as any` can be removed after https://github.com/DefinitelyTyped/DefinitelyTyped/issues/48634 is resolved.
272
+ if (process.env.NODE_ENV !== 'production') {
273
+ this.to.throw(expectedDevMessage);
274
+ }
275
+ else {
276
+ 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.");
277
+ // TODO: Investigate if `as any` can be removed after https://github.com/DefinitelyTyped/DefinitelyTyped/issues/48634 is resolved.
278
+ this.to.throw('Minified MUI error', 'helper');
279
+ }
280
+ });
281
+ function addConsoleMatcher(matcherName, methodName) {
282
+ /**
283
+ * @param {string[]} expectedMessages
284
+ */
285
+ function matcher(expectedMessagesInput = []) {
286
+ // documented pattern to get the actual value of the assertion
287
+ // eslint-disable-next-line no-underscore-dangle
288
+ const callback = this._obj;
289
+ if (process.env.NODE_ENV !== 'production') {
290
+ const expectedMessages = typeof expectedMessagesInput === 'string'
291
+ ? [expectedMessagesInput]
292
+ : expectedMessagesInput.slice();
293
+ const unexpectedMessages = [];
294
+ // TODO Remove type once MUI X enables noImplicitAny
295
+ let caughtError = null;
296
+ this.assert(expectedMessages.length > 0, `Expected to call console.${methodName} but didn't provide messages. ` +
297
+ `If you don't expect any messages prefer \`expect().not.${matcherName}();\`.`, `Expected no call to console.${methodName} while also expecting messages.` +
298
+ 'Expected no call to console.error but provided messages. ' +
299
+ "If you want to make sure a certain message isn't logged prefer the positive. " +
300
+ 'By expecting certain messages you automatically expect that no other messages are logged',
301
+ // Not interested in a diff but the typings require the 4th parameter.
302
+ undefined);
303
+ // Ignore skipped messages in e.g. `[condition && 'foo']`
304
+ const remainingMessages = expectedMessages.filter((messageOrFalse) => {
305
+ return messageOrFalse !== false;
306
+ });
307
+ // eslint-disable-next-line no-console
308
+ const originalMethod = console[methodName];
309
+ let messagesMatched = 0;
310
+ const consoleMatcher = (format, ...args) => {
311
+ // Ignore legacy root deprecation warnings
312
+ // TODO: Remove once we no longer use legacy roots.
313
+ if (format.includes('Use createRoot instead.') ||
314
+ format.includes('Use hydrateRoot instead.')) {
315
+ return;
316
+ }
317
+ const actualMessage = (0, format_util_1.default)(format, ...args);
318
+ const expectedMessage = remainingMessages.shift();
319
+ messagesMatched += 1;
320
+ // TODO Remove type once MUI X enables noImplicitAny
321
+ let message = null;
322
+ if (expectedMessage === undefined) {
323
+ message = `Expected no more error messages but got:\n"${actualMessage}"`;
324
+ }
325
+ else if (!actualMessage.includes(expectedMessage)) {
326
+ message = `Expected #${messagesMatched} "${expectedMessage}" to be included in \n"${actualMessage}"`;
327
+ }
328
+ if (message !== null) {
329
+ const error = new Error(message);
330
+ const { stack: fullStack } = error;
331
+ const fullStacktrace = fullStack.replace(`Error: ${message}\n`, '').split('\n');
332
+ const usefulStacktrace = fullStacktrace
333
+ //
334
+ // first line points to this frame which is irrelevant for the tester
335
+ .slice(1);
336
+ const usefulStack = `${message}\n${usefulStacktrace.join('\n')}`;
337
+ error.stack = usefulStack;
338
+ unexpectedMessages.push(error);
339
+ }
340
+ };
341
+ // eslint-disable-next-line no-console
342
+ console[methodName] = consoleMatcher;
343
+ try {
344
+ callback();
345
+ }
346
+ catch (error) {
347
+ caughtError = error;
348
+ }
349
+ finally {
350
+ // eslint-disable-next-line no-console
351
+ console[methodName] = originalMethod;
352
+ // unexpected thrown error takes precedence over unexpected console call
353
+ if (caughtError !== null) {
354
+ // not the same pattern as described in the block because we don't rethrow in the catch
355
+ // eslint-disable-next-line no-unsafe-finally
356
+ throw caughtError;
357
+ }
358
+ const formatMessages = (messages) => {
359
+ const formattedMessages = messages.map((message) => {
360
+ if (typeof message === 'string') {
361
+ return `"${message}"`;
362
+ }
363
+ // full Error
364
+ return `${message.stack}`;
365
+ });
366
+ return `\n\n - ${formattedMessages.join('\n\n- ')}`;
367
+ };
368
+ const shouldHaveWarned = utils.flag(this, 'negate') !== true;
369
+ // unreachable from expect().not.toWarnDev(messages)
370
+ if (unexpectedMessages.length > 0) {
371
+ const unexpectedMessageRecordedMessage = `Recorded unexpected console.${methodName} calls: ${formatMessages(unexpectedMessages)}`;
372
+ // chai will duplicate the stack frames from the unexpected calls in their assertion error
373
+ // it's not ideal but the test failure is located the second to last stack frame
374
+ // and the origin of the call is the second stackframe in the stack
375
+ this.assert(
376
+ // force chai to always trigger an assertion error
377
+ !shouldHaveWarned, unexpectedMessageRecordedMessage, unexpectedMessageRecordedMessage,
378
+ // Not interested in a diff but the typings require the 4th parameter.
379
+ undefined);
380
+ }
381
+ if (shouldHaveWarned) {
382
+ this.assert(remainingMessages.length === 0, `Could not match the following console.${methodName} calls. ` +
383
+ `Make sure previous actions didn't call console.${methodName} by wrapping them in expect(() => {}).not.${matcherName}(): ${formatMessages(remainingMessages)}`, `Impossible state reached in \`expect().${matcherName}()\`. ` +
384
+ `This is a bug in the matcher.`,
385
+ // Not interested in a diff but the typings require the 4th parameter.
386
+ undefined);
387
+ }
388
+ }
389
+ }
390
+ else {
391
+ // nothing to do in prod
392
+ // If there are still console calls than our test setup throws.
393
+ callback();
394
+ }
395
+ }
396
+ chaiAPI.Assertion.addMethod(matcherName, matcher);
397
+ }
398
+ /**
399
+ * @example expect(() => render()).toWarnDev('single message')
400
+ * @example expect(() => render()).toWarnDev(['first warning', 'then the second'])
401
+ */
402
+ addConsoleMatcher('toWarnDev', 'warn');
403
+ addConsoleMatcher('toErrorDev', 'error');
404
+ };
405
+ exports.default = chaiPlugin;
406
+ //# sourceMappingURL=chaiPlugin.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"chaiPlugin.js","sourceRoot":"","sources":["../src/chaiPlugin.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA,8CAAsD;AACtD,sDAAwD;AACxD,6CAA4C;AAC5C,iEAA4F;AAC5F,8DAAqC;AACrC,oDAAuB;AACvB,wBAAsB;AAEtB,MAAM,OAAO,GAAG,OAAO,CAAC,OAAO,CAAC,GAAG,CAAC,KAAK,CAAC,CAAC;AAE3C,SAAS,SAAS;IAChB,OAAO,OAAO,CAAC,IAAI,CAAC,MAAM,CAAC,SAAS,CAAC,SAAS,CAAC,CAAC;AAClD,CAAC;AAED,gFAAgF;AAChF,SAAS,eAAe,CAAC,OAAmC;IAC1D,IAAI,OAAO,OAAO,EAAE,QAAQ,KAAK,QAAQ,EAAE,CAAC;QAC1C,OAAO,IAAA,gBAAS,EAAC,OAAO,EAAE,SAAS,EAAE,EAAE,SAAS,EAAE,CAAC,OAAO,EAAE,QAAQ,EAAE,CAAC,EAAE,CAAC,CAAC;IAC7E,CAAC;IACD,OAAO,MAAM,CAAC,OAAO,CAAC,CAAC;AACzB,CAAC;AAED,MAAM,UAAU,GAAwC,CAAC,OAAO,EAAE,KAAK,EAAE,EAAE;IACzE,MAAM,aAAa,GAAG,IAAI,GAAG,CAAC;QAC5B,MAAM;QACN,SAAS;QACT,YAAY;QACZ,MAAM;QACN,IAAI;QACJ,KAAK;QACL,IAAI;QACJ,IAAI;QACJ,UAAU;QACV,MAAM;QACN,OAAO;QACP,UAAU;QACV,IAAI;QACJ,IAAI;QACJ,IAAI;QACJ,IAAI;QACJ,IAAI;QACJ,IAAI;QACJ,UAAU;QACV,IAAI;QACJ,GAAG;QACH,IAAI;QACJ,QAAQ;QACR,KAA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,CACV,CAAC;oBACJ,CAAC;gBACH,CAAC;YACH,CAAC;iBAAM,CAAC;gBACN,wBAAwB;gBACxB,+DAA+D;gBAC/D,QAAQ,EAAE,CAAC;YACb,CAAC;QACH,CAAC;QAED,OAAO,CAAC,SAAS,CAAC,SAAS,CAAC,WAAW,EAAE,OAAO,CAAC,CAAC;IACpD,CAAC;IAED;;;OAGG;IACH,iBAAiB,CAAC,WAAW,EAAE,MAAM,CAAC,CAAC;IACvC,iBAAiB,CAAC,YAAY,EAAE,OAAO,CAAC,CAAC;AAC3C,CAAC,CAAC;AAEF,kBAAe,UAAU,CAAC"}
@@ -24,7 +24,7 @@ function createDOM() {
24
24
  pretendToBeVisual: true,
25
25
  url: 'http://localhost',
26
26
  });
27
- global.window = dom.window;
27
+ globalThis.window = dom.window;
28
28
  // Not yet supported: https://github.com/jsdom/jsdom/issues/2152
29
29
  class Touch {
30
30
  constructor(instance) {
@@ -46,13 +46,13 @@ function createDOM() {
46
46
  return this.instance.clientY;
47
47
  }
48
48
  }
49
- global.window.Touch = Touch;
49
+ globalThis.window.Touch = Touch;
50
50
  Object.keys(dom.window)
51
51
  .filter((key) => !blacklist.includes(key))
52
52
  .concat(whitelist)
53
53
  .forEach((key) => {
54
- if (typeof global[key] === 'undefined') {
55
- global[key] = dom.window[key];
54
+ if (typeof globalThis[key] === 'undefined') {
55
+ globalThis[key] = dom.window[key];
56
56
  }
57
57
  });
58
58
  }
@@ -1 +1 @@
1
- {"version":3,"file":"createDOM.js","sourceRoot":"","sources":["../src/createDOM.js"],"names":[],"mappings":";AAAA,MAAM,EAAE,KAAK,EAAE,GAAG,OAAO,CAAC,OAAO,CAAC,CAAC;AAEnC,gFAAgF;AAChF,MAAM,SAAS,GAAG;IAChB,yCAAyC;IACzC,0EAA0E;IAC1E,iBAAiB;IACjB,qCAAqC;IACrC,qBAAqB;IACrB,SAAS;IACT,OAAO;IACP,YAAY;IACZ,OAAO;IACP,aAAa;IACb,kBAAkB;IAClB,MAAM;IAC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