@mui/internal-test-utils 1.0.19 → 1.0.21

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 +41 -19
  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 +39 -20
  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,512 @@
1
+ import { isInaccessible } from '@testing-library/dom';
2
+ import { prettyDOM } from '@testing-library/react/pure';
3
+ import chai, { AssertionError } from 'chai';
4
+ import { computeAccessibleDescription, computeAccessibleName } from 'dom-accessibility-api';
5
+ import formatUtil from 'format-util';
6
+ import _ from 'lodash';
7
+ import './chai.types';
8
+
9
+ const isKarma = Boolean(process.env.KARMA);
10
+
11
+ function isInJSDOM() {
12
+ return /jsdom/.test(window.navigator.userAgent);
13
+ }
14
+
15
+ // chai#utils.elToString that looks like stringified elements in testing-library
16
+ function elementToString(element: Element | null | undefined) {
17
+ if (typeof element?.nodeType === 'number') {
18
+ return prettyDOM(element, undefined, { highlight: !isKarma, maxDepth: 1 });
19
+ }
20
+ return String(element);
21
+ }
22
+
23
+ const chaiPlugin: Parameters<(typeof chai)['use']>[0] = (chaiAPI, utils) => {
24
+ const blockElements = new Set([
25
+ 'html',
26
+ 'address',
27
+ 'blockquote',
28
+ 'body',
29
+ 'dd',
30
+ 'div',
31
+ 'dl',
32
+ 'dt',
33
+ 'fieldset',
34
+ 'form',
35
+ 'frame',
36
+ 'frameset',
37
+ 'h1',
38
+ 'h2',
39
+ 'h3',
40
+ 'h4',
41
+ 'h5',
42
+ 'h6',
43
+ 'noframes',
44
+ 'ol',
45
+ 'p',
46
+ 'ul',
47
+ 'center',
48
+ 'dir',
49
+ 'hr',
50
+ 'menu',
51
+ 'pre',
52
+ ]);
53
+
54
+ function pretendVisibleGetComputedStyle(element: Element): CSSStyleDeclaration {
55
+ // `CSSStyleDeclaration` is not constructable
56
+ // https://stackoverflow.com/a/52732909/3406963
57
+ // this is not equivalent to the declaration from `getComputedStyle`
58
+ // for example `getComputedStyle` would return a readonly declaration
59
+ // let's hope this doesn't get passed around until it's no longer clear where it comes from
60
+ const declaration = document.createElement('span').style;
61
+
62
+ // initial values
63
+ declaration.content = '';
64
+ // technically it's `inline`. We partially apply the default user agent sheet (chrome) here
65
+ // we're only interested in elements that use block
66
+ declaration.display = blockElements.has(element.tagName) ? 'block' : 'inline';
67
+ declaration.visibility = 'visible';
68
+
69
+ return declaration;
70
+ }
71
+
72
+ // better diff view for expect(element).to.equal(document.activeElement)
73
+ chaiAPI.Assertion.addMethod('toHaveFocus', function elementIsFocused() {
74
+ const element = utils.flag(this, 'object');
75
+
76
+ this.assert(
77
+ element === document.activeElement,
78
+ // karma does not show the diff like mocha does
79
+ `expected element to have focus${isKarma ? '\nexpected #{exp}\nactual: #{act}' : ''}`,
80
+ `expected element to NOT have focus \n${elementToString(element)}`,
81
+ elementToString(element),
82
+ elementToString(document.activeElement),
83
+ );
84
+ });
85
+
86
+ chaiAPI.Assertion.addMethod('toHaveVirtualFocus', function elementIsVirtuallyFocused() {
87
+ const element = utils.flag(this, 'object');
88
+ const id = element.getAttribute('id');
89
+
90
+ const virtuallyFocusedElementId = document.activeElement!.getAttribute('aria-activedescendant');
91
+
92
+ this.assert(
93
+ virtuallyFocusedElementId === id,
94
+ `expected element to be virtually focused\nexpected id #{exp}\n${
95
+ virtuallyFocusedElementId === null
96
+ ? `activeElement: ${elementToString(document.activeElement)}`
97
+ : 'actual id: #{act}'
98
+ }`,
99
+ 'expected element to NOT to be virtually focused',
100
+ id,
101
+ virtuallyFocusedElementId,
102
+ virtuallyFocusedElementId !== null,
103
+ );
104
+ });
105
+
106
+ chaiAPI.Assertion.addMethod('toBeInaccessible', function elementIsAccessible() {
107
+ const element = utils.flag(this, 'object');
108
+
109
+ const inaccessible = isInaccessible(element);
110
+
111
+ this.assert(
112
+ inaccessible === true,
113
+ `expected \n${elementToString(element)} to be inaccessible but it was accessible`,
114
+ `expected \n${elementToString(element)} to be accessible but it was inaccessible`,
115
+ // Not interested in a diff but the typings require the 4th parameter.
116
+ undefined,
117
+ );
118
+ });
119
+
120
+ chaiAPI.Assertion.addMethod('toHaveAccessibleName', function hasAccessibleName(expectedName) {
121
+ const root = utils.flag(this, 'object');
122
+ // make sure it's an Element
123
+ new chai.Assertion(root.nodeType, `Expected an Element but got '${String(root)}'`).to.equal(1);
124
+
125
+ const actualName = computeAccessibleName(root, {
126
+ computedStyleSupportsPseudoElements: !isInJSDOM(),
127
+ // in local development we pretend to be visible. full getComputedStyle is
128
+ // expensive and reserved for CI
129
+ getComputedStyle: process.env.CI ? undefined : pretendVisibleGetComputedStyle,
130
+ });
131
+
132
+ this.assert(
133
+ actualName === expectedName,
134
+ `expected \n${elementToString(root)} to have accessible name #{exp} but got #{act} instead.`,
135
+ `expected \n${elementToString(root)} not to have accessible name #{exp}.`,
136
+ expectedName,
137
+ actualName,
138
+ );
139
+ });
140
+
141
+ chaiAPI.Assertion.addMethod(
142
+ 'toHaveAccessibleDescription',
143
+ function hasAccessibleDescription(expectedDescription) {
144
+ const root = utils.flag(this, 'object');
145
+ // make sure it's an Element
146
+ new chai.Assertion(root.nodeType, `Expected an Element but got '${String(root)}'`).to.equal(
147
+ 1,
148
+ );
149
+
150
+ const actualDescription = computeAccessibleDescription(root, {
151
+ // in local development we pretend to be visible. full getComputedStyle is
152
+ // expensive and reserved for CI
153
+ getComputedStyle: process.env.CI ? undefined : pretendVisibleGetComputedStyle,
154
+ });
155
+
156
+ const possibleDescriptionComputationMessage = root.hasAttribute('title')
157
+ ? ' computeAccessibleDescription can be misleading when a `title` attribute is used. This might be a bug in `dom-accessibility-api`.'
158
+ : '';
159
+ this.assert(
160
+ actualDescription === expectedDescription,
161
+ `expected \n${elementToString(
162
+ root,
163
+ )} to have accessible description #{exp} but got #{act} instead.${possibleDescriptionComputationMessage}`,
164
+ `expected \n${elementToString(
165
+ root,
166
+ )} not to have accessible description #{exp}.${possibleDescriptionComputationMessage}`,
167
+ expectedDescription,
168
+ actualDescription,
169
+ );
170
+ },
171
+ );
172
+
173
+ /**
174
+ * Correct name for `to.be.visible`
175
+ */
176
+ chaiAPI.Assertion.addMethod('toBeVisible', function toBeVisible() {
177
+ // eslint-disable-next-line no-underscore-dangle, @typescript-eslint/no-unused-expressions
178
+ new chaiAPI.Assertion(this._obj).to.be.visible;
179
+ });
180
+
181
+ /**
182
+ * Correct name for `not.to.be.visible`
183
+ */
184
+ chaiAPI.Assertion.addMethod('toBeHidden', function toBeHidden() {
185
+ // eslint-disable-next-line no-underscore-dangle, @typescript-eslint/no-unused-expressions
186
+ new chaiAPI.Assertion(this._obj).not.to.be.visible;
187
+ });
188
+
189
+ function assertMatchingStyles(
190
+ this: Chai.AssertionStatic,
191
+ actualStyleDeclaration: CSSStyleDeclaration,
192
+ expectedStyleUnnormalized: Record<string, string>,
193
+ options: { styleTypeHint: string },
194
+ ): void {
195
+ const { styleTypeHint } = options;
196
+
197
+ // Compare objects using hyphen case.
198
+ // This is closer to actual CSS and required for getPropertyValue anyway.
199
+ const expectedStyle: Record<string, string> = {};
200
+ Object.keys(expectedStyleUnnormalized).forEach((cssProperty) => {
201
+ const hyphenCasedPropertyName = _.kebabCase(cssProperty);
202
+ const isVendorPrefixed = /^(moz|ms|o|webkit)-/.test(hyphenCasedPropertyName);
203
+ const propertyName = isVendorPrefixed
204
+ ? `-${hyphenCasedPropertyName}`
205
+ : hyphenCasedPropertyName;
206
+ expectedStyle[propertyName] = expectedStyleUnnormalized[cssProperty];
207
+ });
208
+
209
+ const shorthandProperties = new Set([
210
+ 'all',
211
+ 'animation',
212
+ 'background',
213
+ 'border',
214
+ 'border-block-end',
215
+ 'border-block-start',
216
+ 'border-bottom',
217
+ 'border-color',
218
+ 'border-image',
219
+ 'border-inline-end',
220
+ 'border-inline-start',
221
+ 'border-left',
222
+ 'border-radius',
223
+ 'border-right',
224
+ 'border-style',
225
+ 'border-top',
226
+ 'border-width',
227
+ 'column-rule',
228
+ 'columns',
229
+ 'flex',
230
+ 'flex-flow',
231
+ 'font',
232
+ 'gap',
233
+ 'grid',
234
+ 'grid-area',
235
+ 'grid-column',
236
+ 'grid-row',
237
+ 'grid-template',
238
+ 'list-style',
239
+ 'margin',
240
+ 'mask',
241
+ 'offset',
242
+ 'outline',
243
+ 'overflow',
244
+ 'padding',
245
+ 'place-content',
246
+ 'place-items',
247
+ 'place-self',
248
+ 'scroll-margin',
249
+ 'scroll-padding',
250
+ 'text-decoration',
251
+ 'text-emphasis',
252
+ 'transition',
253
+ ]);
254
+ const usedShorthandProperties = Object.keys(expectedStyle).filter((cssProperty) => {
255
+ return shorthandProperties.has(cssProperty);
256
+ });
257
+ if (usedShorthandProperties.length > 0) {
258
+ throw new Error(
259
+ [
260
+ `Shorthand properties are not supported in ${styleTypeHint} styles matchers since browsers can compute them differently. `,
261
+ 'Use longhand properties instead for the follow shorthand properties:\n',
262
+ usedShorthandProperties
263
+ .map((cssProperty) => {
264
+ return `- https://developer.mozilla.org/en-US/docs/Web/CSS/${cssProperty}#constituent_properties`;
265
+ })
266
+ .join('\n'),
267
+ ].join(''),
268
+ );
269
+ }
270
+
271
+ const actualStyle: Record<string, string> = {};
272
+ Object.keys(expectedStyle).forEach((cssProperty) => {
273
+ actualStyle[cssProperty] = actualStyleDeclaration.getPropertyValue(cssProperty);
274
+ });
275
+
276
+ const jsdomHint =
277
+ 'Styles in JSDOM e.g. from `test:unit` are often misleading since JSDOM does not implement the Cascade nor actual CSS property value computation. ' +
278
+ 'If results differ between real browsers and JSDOM, skip the test in JSDOM e.g. `if (/jsdom/.test(window.navigator.userAgent)) this.skip();`';
279
+ const shorthandHint =
280
+ 'Browsers can compute shorthand properties differently. Prefer longhand properties e.g. `borderTopColor`, `borderRightColor` etc. instead of `border` or `border-color`.';
281
+ const messageHint = `${jsdomHint}\n${shorthandHint}`;
282
+
283
+ if (isKarma) {
284
+ // `#{exp}` and `#{act}` placeholders escape the newlines
285
+ const expected = JSON.stringify(expectedStyle, null, 2);
286
+ const actual = JSON.stringify(actualStyle, null, 2);
287
+ // karma's `dots` reporter does not support diffs
288
+ this.assert(
289
+ // TODO Fix upstream docs/types
290
+ (utils as any).eql(actualStyle, expectedStyle),
291
+ `expected ${styleTypeHint} style of #{this} did not match\nExpected:\n${expected}\nActual:\n${actual}\n\n\n${messageHint}`,
292
+ `expected #{this} to not have ${styleTypeHint} style\n${expected}\n\n\n${messageHint}`,
293
+ expectedStyle,
294
+ actualStyle,
295
+ );
296
+ } else {
297
+ this.assert(
298
+ // TODO Fix upstream docs/types
299
+ (utils as any).eql(actualStyle, expectedStyle),
300
+ `expected #{this} to have ${styleTypeHint} style #{exp} \n\n${messageHint}`,
301
+ `expected #{this} not to have ${styleTypeHint} style #{exp}${messageHint}`,
302
+ expectedStyle,
303
+ actualStyle,
304
+ true,
305
+ );
306
+ }
307
+ }
308
+
309
+ chaiAPI.Assertion.addMethod(
310
+ 'toHaveInlineStyle',
311
+ function toHaveInlineStyle(expectedStyleUnnormalized: Record<string, string>) {
312
+ const element = utils.flag(this, 'object') as HTMLElement;
313
+ if (element?.nodeType !== 1) {
314
+ // Same pre-condition for negated and unnegated assertion
315
+ throw new AssertionError(`Expected an Element but got ${String(element)}`);
316
+ }
317
+
318
+ assertMatchingStyles.call(this, element.style, expectedStyleUnnormalized, {
319
+ styleTypeHint: 'inline',
320
+ });
321
+ },
322
+ );
323
+
324
+ chaiAPI.Assertion.addMethod(
325
+ 'toHaveComputedStyle',
326
+ function toHaveComputedStyle(expectedStyleUnnormalized: Record<string, string>) {
327
+ const element = utils.flag(this, 'object') as HTMLElement;
328
+ if (element?.nodeType !== 1) {
329
+ // Same pre-condition for negated and unnegated assertion
330
+ throw new AssertionError(`Expected an Element but got ${String(element)}`);
331
+ }
332
+ const computedStyle = element.ownerDocument.defaultView!.getComputedStyle(element);
333
+
334
+ assertMatchingStyles.call(this, computedStyle, expectedStyleUnnormalized, {
335
+ styleTypeHint: 'computed',
336
+ });
337
+ },
338
+ );
339
+
340
+ chaiAPI.Assertion.addMethod('toThrowMinified', function toThrowMinified(expectedDevMessage) {
341
+ // TODO: Investigate if `as any` can be removed after https://github.com/DefinitelyTyped/DefinitelyTyped/issues/48634 is resolved.
342
+ if (process.env.NODE_ENV !== 'production') {
343
+ (this as any).to.throw(expectedDevMessage);
344
+ } else {
345
+ utils.flag(
346
+ this,
347
+ 'message',
348
+ "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.",
349
+ );
350
+ // TODO: Investigate if `as any` can be removed after https://github.com/DefinitelyTyped/DefinitelyTyped/issues/48634 is resolved.
351
+ (this as any).to.throw('Minified MUI error', 'helper');
352
+ }
353
+ });
354
+
355
+ function addConsoleMatcher(matcherName: string, methodName: 'error' | 'warn') {
356
+ /**
357
+ * @param {string[]} expectedMessages
358
+ */
359
+ function matcher(this: Chai.AssertionStatic, expectedMessagesInput = []) {
360
+ // documented pattern to get the actual value of the assertion
361
+ // eslint-disable-next-line no-underscore-dangle
362
+ const callback = this._obj;
363
+
364
+ if (process.env.NODE_ENV !== 'production') {
365
+ const expectedMessages =
366
+ typeof expectedMessagesInput === 'string'
367
+ ? [expectedMessagesInput]
368
+ : expectedMessagesInput.slice();
369
+ const unexpectedMessages: Error[] = [];
370
+ // TODO Remove type once MUI X enables noImplicitAny
371
+ let caughtError: unknown | null = null;
372
+
373
+ this.assert(
374
+ expectedMessages.length > 0,
375
+ `Expected to call console.${methodName} but didn't provide messages. ` +
376
+ `If you don't expect any messages prefer \`expect().not.${matcherName}();\`.`,
377
+ `Expected no call to console.${methodName} while also expecting messages.` +
378
+ 'Expected no call to console.error but provided messages. ' +
379
+ "If you want to make sure a certain message isn't logged prefer the positive. " +
380
+ 'By expecting certain messages you automatically expect that no other messages are logged',
381
+ // Not interested in a diff but the typings require the 4th parameter.
382
+ undefined,
383
+ );
384
+
385
+ // Ignore skipped messages in e.g. `[condition && 'foo']`
386
+ const remainingMessages = expectedMessages.filter((messageOrFalse) => {
387
+ return messageOrFalse !== false;
388
+ });
389
+
390
+ // eslint-disable-next-line no-console
391
+ const originalMethod = console[methodName];
392
+
393
+ let messagesMatched = 0;
394
+ const consoleMatcher = (format: string, ...args: readonly unknown[]) => {
395
+ // Ignore legacy root deprecation warnings
396
+ // TODO: Remove once we no longer use legacy roots.
397
+ if (
398
+ format.includes('Use createRoot instead.') ||
399
+ format.includes('Use hydrateRoot instead.')
400
+ ) {
401
+ return;
402
+ }
403
+ const actualMessage = formatUtil(format, ...args);
404
+ const expectedMessage = remainingMessages.shift();
405
+ messagesMatched += 1;
406
+
407
+ // TODO Remove type once MUI X enables noImplicitAny
408
+ let message: string | null = null;
409
+ if (expectedMessage === undefined) {
410
+ message = `Expected no more error messages but got:\n"${actualMessage}"`;
411
+ } else if (!actualMessage.includes(expectedMessage)) {
412
+ message = `Expected #${messagesMatched} "${expectedMessage}" to be included in \n"${actualMessage}"`;
413
+ }
414
+
415
+ if (message !== null) {
416
+ const error = new Error(message);
417
+
418
+ const { stack: fullStack } = error;
419
+ const fullStacktrace = fullStack!.replace(`Error: ${message}\n`, '').split('\n');
420
+
421
+ const usefulStacktrace = fullStacktrace
422
+ //
423
+ // first line points to this frame which is irrelevant for the tester
424
+ .slice(1);
425
+ const usefulStack = `${message}\n${usefulStacktrace.join('\n')}`;
426
+
427
+ error.stack = usefulStack;
428
+ unexpectedMessages.push(error);
429
+ }
430
+ };
431
+ // eslint-disable-next-line no-console
432
+ console[methodName] = consoleMatcher;
433
+
434
+ try {
435
+ callback();
436
+ } catch (error) {
437
+ caughtError = error;
438
+ } finally {
439
+ // eslint-disable-next-line no-console
440
+ console[methodName] = originalMethod;
441
+
442
+ // unexpected thrown error takes precedence over unexpected console call
443
+ if (caughtError !== null) {
444
+ // not the same pattern as described in the block because we don't rethrow in the catch
445
+ // eslint-disable-next-line no-unsafe-finally
446
+ throw caughtError;
447
+ }
448
+
449
+ const formatMessages = (messages: ReadonlyArray<Error | string>) => {
450
+ const formattedMessages = messages.map((message) => {
451
+ if (typeof message === 'string') {
452
+ return `"${message}"`;
453
+ }
454
+ // full Error
455
+ return `${message.stack}`;
456
+ });
457
+ return `\n\n - ${formattedMessages.join('\n\n- ')}`;
458
+ };
459
+
460
+ const shouldHaveWarned = utils.flag(this, 'negate') !== true;
461
+
462
+ // unreachable from expect().not.toWarnDev(messages)
463
+ if (unexpectedMessages.length > 0) {
464
+ const unexpectedMessageRecordedMessage = `Recorded unexpected console.${methodName} calls: ${formatMessages(
465
+ unexpectedMessages,
466
+ )}`;
467
+ // chai will duplicate the stack frames from the unexpected calls in their assertion error
468
+ // it's not ideal but the test failure is located the second to last stack frame
469
+ // and the origin of the call is the second stackframe in the stack
470
+ this.assert(
471
+ // force chai to always trigger an assertion error
472
+ !shouldHaveWarned,
473
+ unexpectedMessageRecordedMessage,
474
+ unexpectedMessageRecordedMessage,
475
+ // Not interested in a diff but the typings require the 4th parameter.
476
+ undefined,
477
+ );
478
+ }
479
+
480
+ if (shouldHaveWarned) {
481
+ this.assert(
482
+ remainingMessages.length === 0,
483
+ `Could not match the following console.${methodName} calls. ` +
484
+ `Make sure previous actions didn't call console.${methodName} by wrapping them in expect(() => {}).not.${matcherName}(): ${formatMessages(
485
+ remainingMessages,
486
+ )}`,
487
+ `Impossible state reached in \`expect().${matcherName}()\`. ` +
488
+ `This is a bug in the matcher.`,
489
+ // Not interested in a diff but the typings require the 4th parameter.
490
+ undefined,
491
+ );
492
+ }
493
+ }
494
+ } else {
495
+ // nothing to do in prod
496
+ // If there are still console calls than our test setup throws.
497
+ callback();
498
+ }
499
+ }
500
+
501
+ chaiAPI.Assertion.addMethod(matcherName, matcher);
502
+ }
503
+
504
+ /**
505
+ * @example expect(() => render()).toWarnDev('single message')
506
+ * @example expect(() => render()).toWarnDev(['first warning', 'then the second'])
507
+ */
508
+ addConsoleMatcher('toWarnDev', 'warn');
509
+ addConsoleMatcher('toErrorDev', 'error');
510
+ };
511
+
512
+ export default chaiPlugin;
package/src/createDOM.js CHANGED
@@ -25,7 +25,7 @@ function createDOM() {
25
25
  pretendToBeVisual: true,
26
26
  url: 'http://localhost',
27
27
  });
28
- global.window = dom.window;
28
+ globalThis.window = dom.window;
29
29
  // Not yet supported: https://github.com/jsdom/jsdom/issues/2152
30
30
  class Touch {
31
31
  constructor(instance) {
@@ -52,14 +52,14 @@ function createDOM() {
52
52
  return this.instance.clientY;
53
53
  }
54
54
  }
55
- global.window.Touch = Touch;
55
+ globalThis.window.Touch = Touch;
56
56
 
57
57
  Object.keys(dom.window)
58
58
  .filter((key) => !blacklist.includes(key))
59
59
  .concat(whitelist)
60
60
  .forEach((key) => {
61
- if (typeof global[key] === 'undefined') {
62
- global[key] = dom.window[key];
61
+ if (typeof globalThis[key] === 'undefined') {
62
+ globalThis[key] = dom.window[key];
63
63
  }
64
64
  });
65
65
  }