@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.
- package/{src/chai.types.ts → chai.types.d.ts} +7 -40
- package/chai.types.js +5 -0
- package/chaiPlugin.d.ts +4 -0
- package/chaiPlugin.js +287 -0
- package/{build/components.d.ts → components.d.ts} +18 -19
- package/components.js +64 -0
- package/createDOM.d.ts +2 -0
- package/{src/createDOM.js → createDOM.js} +17 -35
- package/createDescribe.d.ts +7 -0
- package/createDescribe.js +26 -0
- package/createRenderer.d.ts +214 -0
- package/createRenderer.js +428 -0
- package/createRenderer.test.d.ts +1 -0
- package/describeConformance.d.ts +200 -0
- package/describeConformance.js +1038 -0
- package/env.d.ts +1 -0
- package/env.js +11 -0
- package/esm/chai.types.d.ts +74 -0
- package/esm/chai.types.js +3 -0
- package/esm/chaiPlugin.d.ts +4 -0
- package/esm/chaiPlugin.js +281 -0
- package/esm/components.d.ts +35 -0
- package/esm/components.js +56 -0
- package/esm/createDOM.d.ts +2 -0
- package/esm/createDOM.js +47 -0
- package/esm/createDescribe.d.ts +7 -0
- package/esm/createDescribe.js +19 -0
- package/esm/createRenderer.d.ts +214 -0
- package/esm/createRenderer.js +390 -0
- package/esm/createRenderer.test.d.ts +1 -0
- package/esm/describeConformance.d.ts +200 -0
- package/esm/describeConformance.js +1024 -0
- package/esm/env.d.ts +1 -0
- package/esm/env.js +5 -0
- package/{build → esm}/fireDiscreteEvent.d.ts +1 -2
- package/{src/fireDiscreteEvent.ts → esm/fireDiscreteEvent.js} +10 -18
- package/esm/flushMicrotasks.d.ts +1 -0
- package/{src/flushMicrotasks.ts → esm/flushMicrotasks.js} +2 -3
- package/{build → esm}/focusVisible.d.ts +1 -2
- package/{src/focusVisible.ts → esm/focusVisible.js} +10 -9
- package/esm/index.d.ts +18 -0
- package/esm/index.js +27 -0
- package/esm/init.d.ts +1 -0
- package/{src → esm}/init.js +4 -2
- package/esm/initMatchers.d.ts +1 -0
- package/esm/initMatchers.js +6 -0
- package/esm/initMatchers.test.d.ts +1 -0
- package/esm/initPlaywrightMatchers.d.ts +24 -0
- package/esm/initPlaywrightMatchers.js +40 -0
- package/esm/package.json +1 -0
- package/esm/reactMajor.d.ts +2 -0
- package/esm/reactMajor.js +2 -0
- package/esm/setup.d.ts +1 -0
- package/{src → esm}/setup.js +2 -4
- package/esm/setupVitest.d.ts +1 -0
- package/esm/setupVitest.js +28 -0
- package/esm/setupVitestBrowser.d.ts +1 -0
- package/esm/setupVitestBrowser.js +30 -0
- package/fireDiscreteEvent.d.ts +6 -0
- package/fireDiscreteEvent.js +79 -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 +18 -0
- package/index.js +139 -0
- package/init.d.ts +1 -0
- package/init.js +15 -0
- package/initMatchers.d.ts +1 -0
- package/initMatchers.js +10 -0
- package/initMatchers.test.d.ts +1 -0
- package/initPlaywrightMatchers.d.ts +24 -0
- package/initPlaywrightMatchers.js +42 -0
- package/package.json +89 -46
- package/reactMajor.d.ts +2 -0
- package/reactMajor.js +9 -0
- package/setup.d.ts +1 -0
- package/setup.js +10 -0
- package/setupVitest.d.ts +1 -0
- package/setupVitest.js +32 -0
- package/setupVitestBrowser.d.ts +1 -0
- package/setupVitestBrowser.js +34 -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.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/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/index.ts +0 -25
- 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/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/esm/env.d.ts
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export declare function isJsdom(): boolean;
|
package/esm/env.js
ADDED
|
@@ -3,5 +3,4 @@ export declare function click(...args: Parameters<(typeof fireEvent)['click']>):
|
|
|
3
3
|
export declare function keyDown(...args: Parameters<(typeof fireEvent)['keyDown']>): void;
|
|
4
4
|
export declare function keyUp(...args: Parameters<(typeof fireEvent)['keyUp']>): void;
|
|
5
5
|
export declare function mouseDown(...args: Parameters<(typeof fireEvent)['mouseDown']>): void;
|
|
6
|
-
export declare function mouseUp(...args: Parameters<(typeof fireEvent)['mouseUp']>): void;
|
|
7
|
-
//# sourceMappingURL=fireDiscreteEvent.d.ts.map
|
|
6
|
+
export declare function mouseUp(...args: Parameters<(typeof fireEvent)['mouseUp']>): void;
|
|
@@ -1,18 +1,16 @@
|
|
|
1
1
|
import { configure, fireEvent, getConfig } from '@testing-library/react/pure';
|
|
2
|
-
import reactMajor from
|
|
3
|
-
|
|
4
|
-
const noWrapper = (callback: () => void) => callback();
|
|
2
|
+
import reactMajor from "./reactMajor.js";
|
|
3
|
+
const noWrapper = callback => callback();
|
|
5
4
|
|
|
6
5
|
/**
|
|
7
6
|
* @param {() => void} callback
|
|
8
7
|
* @returns {void}
|
|
9
8
|
*/
|
|
10
|
-
function withMissingActWarningsIgnored(callback
|
|
9
|
+
function withMissingActWarningsIgnored(callback) {
|
|
11
10
|
if (reactMajor >= 18) {
|
|
12
11
|
callback();
|
|
13
12
|
return;
|
|
14
13
|
}
|
|
15
|
-
|
|
16
14
|
const originalConsoleError = console.error;
|
|
17
15
|
console.error = function silenceMissingActWarnings(message, ...args) {
|
|
18
16
|
const isMissingActWarning = /not wrapped in act\(...\)/.test(message);
|
|
@@ -20,12 +18,10 @@ function withMissingActWarningsIgnored(callback: () => void) {
|
|
|
20
18
|
originalConsoleError.call(console, message, ...args);
|
|
21
19
|
}
|
|
22
20
|
};
|
|
23
|
-
|
|
24
21
|
const originalConfig = getConfig();
|
|
25
22
|
configure({
|
|
26
|
-
eventWrapper: noWrapper
|
|
23
|
+
eventWrapper: noWrapper
|
|
27
24
|
});
|
|
28
|
-
|
|
29
25
|
try {
|
|
30
26
|
callback();
|
|
31
27
|
} finally {
|
|
@@ -45,32 +41,28 @@ function withMissingActWarningsIgnored(callback: () => void) {
|
|
|
45
41
|
// Note that using `fireEvent` from `@testing-library/dom` would not work since /react configures both `fireEvent` to use `act` as a wrapper.
|
|
46
42
|
// -----------------------------------------
|
|
47
43
|
|
|
48
|
-
export function click(...args
|
|
44
|
+
export function click(...args) {
|
|
49
45
|
return withMissingActWarningsIgnored(() => {
|
|
50
46
|
fireEvent.click(...args);
|
|
51
47
|
});
|
|
52
48
|
}
|
|
53
|
-
|
|
54
|
-
export function keyDown(...args: Parameters<(typeof fireEvent)['keyDown']>) {
|
|
49
|
+
export function keyDown(...args) {
|
|
55
50
|
return withMissingActWarningsIgnored(() => {
|
|
56
51
|
fireEvent.keyDown(...args);
|
|
57
52
|
});
|
|
58
53
|
}
|
|
59
|
-
|
|
60
|
-
export function keyUp(...args: Parameters<(typeof fireEvent)['keyUp']>) {
|
|
54
|
+
export function keyUp(...args) {
|
|
61
55
|
return withMissingActWarningsIgnored(() => {
|
|
62
56
|
fireEvent.keyUp(...args);
|
|
63
57
|
});
|
|
64
58
|
}
|
|
65
|
-
|
|
66
|
-
export function mouseDown(...args: Parameters<(typeof fireEvent)['mouseDown']>) {
|
|
59
|
+
export function mouseDown(...args) {
|
|
67
60
|
return withMissingActWarningsIgnored(() => {
|
|
68
61
|
fireEvent.mouseDown(...args);
|
|
69
62
|
});
|
|
70
63
|
}
|
|
71
|
-
|
|
72
|
-
export function mouseUp(...args: Parameters<(typeof fireEvent)['mouseUp']>) {
|
|
64
|
+
export function mouseUp(...args) {
|
|
73
65
|
return withMissingActWarningsIgnored(() => {
|
|
74
66
|
fireEvent.mouseUp(...args);
|
|
75
67
|
});
|
|
76
|
-
}
|
|
68
|
+
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export default function flushMicrotasks(): Promise<void>;
|
|
@@ -4,5 +4,4 @@ export declare function simulateKeyboardDevice(): void;
|
|
|
4
4
|
/**
|
|
5
5
|
* See https://issues.chromium.org/issues/40719291 for more details.
|
|
6
6
|
*/
|
|
7
|
-
export declare function programmaticFocusTriggersFocusVisible(): boolean;
|
|
8
|
-
//# sourceMappingURL=focusVisible.d.ts.map
|
|
7
|
+
export declare function programmaticFocusTriggersFocusVisible(): boolean;
|
|
@@ -1,29 +1,30 @@
|
|
|
1
|
-
import { act, fireEvent } from
|
|
2
|
-
|
|
3
|
-
export default function focusVisible(element: HTMLElement) {
|
|
1
|
+
import { act, fireEvent } from "./createRenderer.js";
|
|
2
|
+
export default function focusVisible(element) {
|
|
4
3
|
act(() => {
|
|
5
4
|
element.blur();
|
|
6
5
|
});
|
|
7
|
-
fireEvent.keyDown(document.body, {
|
|
6
|
+
fireEvent.keyDown(document.body, {
|
|
7
|
+
key: 'Tab'
|
|
8
|
+
});
|
|
8
9
|
act(() => {
|
|
9
10
|
element.focus();
|
|
10
11
|
});
|
|
11
12
|
}
|
|
12
|
-
|
|
13
13
|
export function simulatePointerDevice() {
|
|
14
14
|
// first focus on a page triggers focus visible until a pointer event
|
|
15
15
|
// has been dispatched
|
|
16
16
|
fireEvent.pointerDown(document.body);
|
|
17
17
|
}
|
|
18
|
-
|
|
19
18
|
export function simulateKeyboardDevice() {
|
|
20
|
-
fireEvent.keyDown(document.body, {
|
|
19
|
+
fireEvent.keyDown(document.body, {
|
|
20
|
+
key: 'TAB'
|
|
21
|
+
});
|
|
21
22
|
}
|
|
22
23
|
|
|
23
24
|
/**
|
|
24
25
|
* See https://issues.chromium.org/issues/40719291 for more details.
|
|
25
26
|
*/
|
|
26
|
-
export function programmaticFocusTriggersFocusVisible()
|
|
27
|
+
export function programmaticFocusTriggersFocusVisible() {
|
|
27
28
|
try {
|
|
28
29
|
// So far this only applies to Chrome 86 beta which is the only tested browser supporting this pseudo class.
|
|
29
30
|
document.createElement('button').matches(':focus-visible');
|
|
@@ -31,4 +32,4 @@ export function programmaticFocusTriggersFocusVisible(): boolean {
|
|
|
31
32
|
} catch (error) {
|
|
32
33
|
return false;
|
|
33
34
|
}
|
|
34
|
-
}
|
|
35
|
+
}
|
package/esm/index.d.ts
ADDED
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
export * from "./components.js";
|
|
2
|
+
export { default as describeConformance } from "./describeConformance.js";
|
|
3
|
+
export * from "./describeConformance.js";
|
|
4
|
+
export { default as createDescribe } from "./createDescribe.js";
|
|
5
|
+
export * from "./createRenderer.js";
|
|
6
|
+
export { default as focusVisible, simulatePointerDevice, simulateKeyboardDevice, programmaticFocusTriggersFocusVisible } from "./focusVisible.js";
|
|
7
|
+
export {} from "./initMatchers.js";
|
|
8
|
+
export * as fireDiscreteEvent from "./fireDiscreteEvent.js";
|
|
9
|
+
export { default as flushMicrotasks } from "./flushMicrotasks.js";
|
|
10
|
+
export { default as reactMajor } from "./reactMajor.js";
|
|
11
|
+
export * from "./env.js";
|
|
12
|
+
/**
|
|
13
|
+
* Set to true if console logs during [lifecycles that are invoked twice in `React.StrictMode`](https://reactjs.org/docs/strict-mode.html#detecting-unexpected-side-effects) are suppressed.
|
|
14
|
+
* Useful for asserting on `console.warn` or `console.error` via `toErrorDev()`.
|
|
15
|
+
* TODO: Refactor to use reactMajor when fixing the React 17 cron test.
|
|
16
|
+
* https://github.com/mui/material-ui/issues/43153
|
|
17
|
+
*/
|
|
18
|
+
export declare const strictModeDoubleLoggingSuppressed: boolean;
|
package/esm/index.js
ADDED
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @mui/internal-test-utils v2.0.16
|
|
3
|
+
*
|
|
4
|
+
* @license undefined
|
|
5
|
+
* This source code is licensed under the undefined license found in the
|
|
6
|
+
* LICENSE file in the root directory of this source tree.
|
|
7
|
+
*/
|
|
8
|
+
import * as React from 'react';
|
|
9
|
+
export * from "./components.js";
|
|
10
|
+
export { default as describeConformance } from "./describeConformance.js";
|
|
11
|
+
export * from "./describeConformance.js";
|
|
12
|
+
export { default as createDescribe } from "./createDescribe.js";
|
|
13
|
+
export * from "./createRenderer.js";
|
|
14
|
+
export { default as focusVisible, simulatePointerDevice, simulateKeyboardDevice, programmaticFocusTriggersFocusVisible } from "./focusVisible.js";
|
|
15
|
+
export {} from "./initMatchers.js";
|
|
16
|
+
export * as fireDiscreteEvent from "./fireDiscreteEvent.js";
|
|
17
|
+
export { default as flushMicrotasks } from "./flushMicrotasks.js";
|
|
18
|
+
export { default as reactMajor } from "./reactMajor.js";
|
|
19
|
+
export * from "./env.js";
|
|
20
|
+
|
|
21
|
+
/**
|
|
22
|
+
* Set to true if console logs during [lifecycles that are invoked twice in `React.StrictMode`](https://reactjs.org/docs/strict-mode.html#detecting-unexpected-side-effects) are suppressed.
|
|
23
|
+
* Useful for asserting on `console.warn` or `console.error` via `toErrorDev()`.
|
|
24
|
+
* TODO: Refactor to use reactMajor when fixing the React 17 cron test.
|
|
25
|
+
* https://github.com/mui/material-ui/issues/43153
|
|
26
|
+
*/
|
|
27
|
+
export const strictModeDoubleLoggingSuppressed = React.version.startsWith('17');
|
package/esm/init.d.ts
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
package/{src → esm}/init.js
RENAMED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import * as testingLibrary from '@testing-library/react/pure';
|
|
2
|
-
import
|
|
2
|
+
import "./initMatchers.js";
|
|
3
3
|
|
|
4
4
|
// checking if an element is hidden is quite expensive
|
|
5
5
|
// this is only done in CI as a fail safe. It can still explicitly be checked
|
|
@@ -8,4 +8,6 @@ import './initMatchers';
|
|
|
8
8
|
const defaultHidden = !process.env.CI;
|
|
9
9
|
// adds verbosity for something that might be confusing
|
|
10
10
|
console.warn(`${defaultHidden ? 'including' : 'excluding'} inaccessible elements by default`);
|
|
11
|
-
testingLibrary.configure({
|
|
11
|
+
testingLibrary.configure({
|
|
12
|
+
defaultHidden
|
|
13
|
+
});
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
import "./chai.types.js";
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
import * as DomTestingLibrary from '@testing-library/dom';
|
|
2
|
+
declare global {
|
|
3
|
+
namespace Chai {
|
|
4
|
+
interface Assertion {
|
|
5
|
+
/**
|
|
6
|
+
* Checks if the element handle is actually focused i.e. the element handle is pointing to `document.activeElement`.
|
|
7
|
+
*/
|
|
8
|
+
toHaveFocus(): Promise<void>;
|
|
9
|
+
/**
|
|
10
|
+
* Checks if the element handle has the given attribute.
|
|
11
|
+
* @example expect($element).toHaveAttribute('aria-expanded') is like `[aria-expanded]` CSS selector
|
|
12
|
+
* @example expect($element).toHaveAttribute('aria-expanded', 'true') is like `[aria-expanded="true"]` CSS selector
|
|
13
|
+
*/
|
|
14
|
+
toHaveAttribute(attributeName: string, attributeValue?: string): Promise<void>;
|
|
15
|
+
}
|
|
16
|
+
}
|
|
17
|
+
interface Window {
|
|
18
|
+
DomTestingLibrary: typeof DomTestingLibrary;
|
|
19
|
+
/**
|
|
20
|
+
* @example $element.evaluate(element => window.pageElementToString(element))
|
|
21
|
+
*/
|
|
22
|
+
elementToString(element: Node | null | undefined): string | false;
|
|
23
|
+
}
|
|
24
|
+
}
|
|
@@ -0,0 +1,40 @@
|
|
|
1
|
+
import * as chai from 'chai';
|
|
2
|
+
import { AssertionError } from 'assertion-error';
|
|
3
|
+
|
|
4
|
+
// https://stackoverflow.com/a/46755166/3406963
|
|
5
|
+
|
|
6
|
+
chai.use((chaiAPI, utils) => {
|
|
7
|
+
chai.Assertion.addMethod('toHaveFocus', async function elementHandleIsFocused() {
|
|
8
|
+
const $elementOrHandle = utils.flag(this, 'object');
|
|
9
|
+
if ($elementOrHandle == null) {
|
|
10
|
+
throw new AssertionError(`Expected an element handle but got ${String($elementOrHandle)}.`);
|
|
11
|
+
}
|
|
12
|
+
const $element = typeof $elementOrHandle.then === 'function' ? await $elementOrHandle : $elementOrHandle;
|
|
13
|
+
const {
|
|
14
|
+
isFocused,
|
|
15
|
+
stringifiedActiveElement,
|
|
16
|
+
stringifiedElement
|
|
17
|
+
} = await $element.evaluate(element => {
|
|
18
|
+
const activeElement = element.ownerDocument !== null ? element.ownerDocument.activeElement : null;
|
|
19
|
+
return {
|
|
20
|
+
isFocused: activeElement === element,
|
|
21
|
+
stringifiedElement: window.elementToString(element),
|
|
22
|
+
stringifiedActiveElement: window.elementToString(activeElement)
|
|
23
|
+
};
|
|
24
|
+
});
|
|
25
|
+
this.assert(isFocused, `expected element to have focus`, `expected element to NOT have focus \n${stringifiedElement}`, stringifiedElement, stringifiedActiveElement);
|
|
26
|
+
});
|
|
27
|
+
chai.Assertion.addMethod('toHaveAttribute', async function elementHandleHasAttribute(attributeName, attributeValue) {
|
|
28
|
+
const $elementOrHandle = utils.flag(this, 'object');
|
|
29
|
+
if ($elementOrHandle == null) {
|
|
30
|
+
throw new AssertionError(`Expected an element handle but got ${String($elementOrHandle)}.`);
|
|
31
|
+
}
|
|
32
|
+
const $element = typeof $elementOrHandle.then === 'function' ? await $elementOrHandle : $elementOrHandle;
|
|
33
|
+
const actualAttributeValue = await $element.getAttribute(attributeName);
|
|
34
|
+
if (attributeValue === undefined) {
|
|
35
|
+
this.assert(actualAttributeValue !== null, `expected element to have attribute \`${attributeName}\``, `expected element to NOT have attribute \`${attributeName}\``, null, null);
|
|
36
|
+
} else {
|
|
37
|
+
this.assert(actualAttributeValue === attributeValue, `expected element to have attribute \`${attributeName}="${attributeValue}"\``, `expected element to NOT have attribute \`${attributeName}="${attributeValue}"\``, attributeValue, actualAttributeValue);
|
|
38
|
+
}
|
|
39
|
+
});
|
|
40
|
+
});
|
package/esm/package.json
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"type":"module","sideEffects":false}
|
package/esm/setup.d.ts
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
package/{src → esm}/setup.js
RENAMED
|
@@ -1,10 +1,8 @@
|
|
|
1
1
|
const testingLibrary = require('@testing-library/dom');
|
|
2
2
|
const createDOM = require('./createDOM');
|
|
3
|
-
|
|
4
3
|
createDOM();
|
|
5
4
|
require('./init');
|
|
6
|
-
|
|
7
5
|
testingLibrary.configure({
|
|
8
6
|
// JSDOM logs errors otherwise on `getComputedStyle(element, pseudoElement)` calls.
|
|
9
|
-
computedStyleSupportsPseudoElements: false
|
|
10
|
-
});
|
|
7
|
+
computedStyleSupportsPseudoElements: false
|
|
8
|
+
});
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
import "./chai.types.js";
|
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
import failOnConsole from 'vitest-fail-on-console';
|
|
2
|
+
import * as chai from 'chai';
|
|
3
|
+
import "./chai.types.js";
|
|
4
|
+
import chaiPlugin from "./chaiPlugin.js";
|
|
5
|
+
chai.use(chaiPlugin);
|
|
6
|
+
failOnConsole({
|
|
7
|
+
silenceMessage: message => {
|
|
8
|
+
if (process.env.NODE_ENV === 'production') {
|
|
9
|
+
// TODO: mock scheduler
|
|
10
|
+
if (message.includes('act(...) is not supported in production builds of React')) {
|
|
11
|
+
return true;
|
|
12
|
+
}
|
|
13
|
+
}
|
|
14
|
+
if (message.includes('Warning: useLayoutEffect does nothing on the server')) {
|
|
15
|
+
// Controversial warning that is commonly ignored by switching to `useEffect` on the server.
|
|
16
|
+
// https://github.com/facebook/react/issues/14927
|
|
17
|
+
// However, this switch doesn't work since it relies on environment sniffing and we test SSR in a browser environment.
|
|
18
|
+
return true;
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
// Unclear why this is an issue for the current occurrences of this warning.
|
|
22
|
+
// TODO: Revisit once https://github.com/facebook/react/issues/22796 is resolved
|
|
23
|
+
if (message.includes('Detected multiple renderers concurrently rendering the same context provider.')) {
|
|
24
|
+
return true;
|
|
25
|
+
}
|
|
26
|
+
return false;
|
|
27
|
+
}
|
|
28
|
+
});
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
import * as chai from 'chai';
|
|
2
|
+
import chaiDom from 'chai-dom';
|
|
3
|
+
chai.use(chaiDom);
|
|
4
|
+
|
|
5
|
+
// Enable missing act warnings: https://github.com/reactwg/react-18/discussions/102
|
|
6
|
+
globalThis.jest = null;
|
|
7
|
+
globalThis.IS_REACT_ACT_ENVIRONMENT = true;
|
|
8
|
+
if (window.navigator.userAgent.includes('jsdom')) {
|
|
9
|
+
// Not yet supported: https://github.com/jsdom/jsdom/issues/2152
|
|
10
|
+
globalThis.window.Touch = class Touch {
|
|
11
|
+
constructor(instance) {
|
|
12
|
+
this.instance = instance;
|
|
13
|
+
}
|
|
14
|
+
get identifier() {
|
|
15
|
+
return this.instance.identifier;
|
|
16
|
+
}
|
|
17
|
+
get pageX() {
|
|
18
|
+
return this.instance.pageX;
|
|
19
|
+
}
|
|
20
|
+
get pageY() {
|
|
21
|
+
return this.instance.pageY;
|
|
22
|
+
}
|
|
23
|
+
get clientX() {
|
|
24
|
+
return this.instance.clientX;
|
|
25
|
+
}
|
|
26
|
+
get clientY() {
|
|
27
|
+
return this.instance.clientY;
|
|
28
|
+
}
|
|
29
|
+
};
|
|
30
|
+
}
|
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
import { fireEvent } from '@testing-library/react/pure';
|
|
2
|
+
export declare function click(...args: Parameters<(typeof fireEvent)['click']>): void;
|
|
3
|
+
export declare function keyDown(...args: Parameters<(typeof fireEvent)['keyDown']>): void;
|
|
4
|
+
export declare function keyUp(...args: Parameters<(typeof fireEvent)['keyUp']>): void;
|
|
5
|
+
export declare function mouseDown(...args: Parameters<(typeof fireEvent)['mouseDown']>): void;
|
|
6
|
+
export declare function mouseUp(...args: Parameters<(typeof fireEvent)['mouseUp']>): void;
|
|
@@ -0,0 +1,79 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault").default;
|
|
4
|
+
Object.defineProperty(exports, "__esModule", {
|
|
5
|
+
value: true
|
|
6
|
+
});
|
|
7
|
+
exports.click = click;
|
|
8
|
+
exports.keyDown = keyDown;
|
|
9
|
+
exports.keyUp = keyUp;
|
|
10
|
+
exports.mouseDown = mouseDown;
|
|
11
|
+
exports.mouseUp = mouseUp;
|
|
12
|
+
var _pure = require("@testing-library/react/pure");
|
|
13
|
+
var _reactMajor = _interopRequireDefault(require("./reactMajor"));
|
|
14
|
+
const noWrapper = callback => callback();
|
|
15
|
+
|
|
16
|
+
/**
|
|
17
|
+
* @param {() => void} callback
|
|
18
|
+
* @returns {void}
|
|
19
|
+
*/
|
|
20
|
+
function withMissingActWarningsIgnored(callback) {
|
|
21
|
+
if (_reactMajor.default >= 18) {
|
|
22
|
+
callback();
|
|
23
|
+
return;
|
|
24
|
+
}
|
|
25
|
+
const originalConsoleError = console.error;
|
|
26
|
+
console.error = function silenceMissingActWarnings(message, ...args) {
|
|
27
|
+
const isMissingActWarning = /not wrapped in act\(...\)/.test(message);
|
|
28
|
+
if (!isMissingActWarning) {
|
|
29
|
+
originalConsoleError.call(console, message, ...args);
|
|
30
|
+
}
|
|
31
|
+
};
|
|
32
|
+
const originalConfig = (0, _pure.getConfig)();
|
|
33
|
+
(0, _pure.configure)({
|
|
34
|
+
eventWrapper: noWrapper
|
|
35
|
+
});
|
|
36
|
+
try {
|
|
37
|
+
callback();
|
|
38
|
+
} finally {
|
|
39
|
+
(0, _pure.configure)(originalConfig);
|
|
40
|
+
console.error = originalConsoleError;
|
|
41
|
+
}
|
|
42
|
+
}
|
|
43
|
+
|
|
44
|
+
// -----------------------------------------
|
|
45
|
+
// WARNING ⚠️ WARNING ⚠️ WARNING ⚠️ WARNING
|
|
46
|
+
//
|
|
47
|
+
// Do not add events here because you want to ignore "missing act()" warnings.
|
|
48
|
+
// Only add events if you made sure that React actually considers these as "discrete".
|
|
49
|
+
// Be aware that "discrete events" are an implementation detail of React.
|
|
50
|
+
// To test discrete events we cannot use `fireEvent` from `@testing-library/react` because they are all wrapped in `act`.
|
|
51
|
+
// `act` overrides the "discrete event" semantics with "batching" semantics: https://github.com/facebook/react/blob/3fbd47b86285b6b7bdeab66d29c85951a84d4525/packages/react-reconciler/src/ReactFiberWorkLoop.old.js#L1061-L1064
|
|
52
|
+
// Note that using `fireEvent` from `@testing-library/dom` would not work since /react configures both `fireEvent` to use `act` as a wrapper.
|
|
53
|
+
// -----------------------------------------
|
|
54
|
+
|
|
55
|
+
function click(...args) {
|
|
56
|
+
return withMissingActWarningsIgnored(() => {
|
|
57
|
+
_pure.fireEvent.click(...args);
|
|
58
|
+
});
|
|
59
|
+
}
|
|
60
|
+
function keyDown(...args) {
|
|
61
|
+
return withMissingActWarningsIgnored(() => {
|
|
62
|
+
_pure.fireEvent.keyDown(...args);
|
|
63
|
+
});
|
|
64
|
+
}
|
|
65
|
+
function keyUp(...args) {
|
|
66
|
+
return withMissingActWarningsIgnored(() => {
|
|
67
|
+
_pure.fireEvent.keyUp(...args);
|
|
68
|
+
});
|
|
69
|
+
}
|
|
70
|
+
function mouseDown(...args) {
|
|
71
|
+
return withMissingActWarningsIgnored(() => {
|
|
72
|
+
_pure.fireEvent.mouseDown(...args);
|
|
73
|
+
});
|
|
74
|
+
}
|
|
75
|
+
function mouseUp(...args) {
|
|
76
|
+
return withMissingActWarningsIgnored(() => {
|
|
77
|
+
_pure.fireEvent.mouseUp(...args);
|
|
78
|
+
});
|
|
79
|
+
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export default function flushMicrotasks(): Promise<void>;
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, "__esModule", {
|
|
4
|
+
value: true
|
|
5
|
+
});
|
|
6
|
+
exports.default = flushMicrotasks;
|
|
7
|
+
var _createRenderer = require("./createRenderer");
|
|
8
|
+
async function flushMicrotasks() {
|
|
9
|
+
await (0, _createRenderer.act)(async () => {});
|
|
10
|
+
}
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
export default function focusVisible(element: HTMLElement): void;
|
|
2
|
+
export declare function simulatePointerDevice(): void;
|
|
3
|
+
export declare function simulateKeyboardDevice(): void;
|
|
4
|
+
/**
|
|
5
|
+
* See https://issues.chromium.org/issues/40719291 for more details.
|
|
6
|
+
*/
|
|
7
|
+
export declare function programmaticFocusTriggersFocusVisible(): boolean;
|
package/focusVisible.js
ADDED
|
@@ -0,0 +1,44 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, "__esModule", {
|
|
4
|
+
value: true
|
|
5
|
+
});
|
|
6
|
+
exports.default = focusVisible;
|
|
7
|
+
exports.programmaticFocusTriggersFocusVisible = programmaticFocusTriggersFocusVisible;
|
|
8
|
+
exports.simulateKeyboardDevice = simulateKeyboardDevice;
|
|
9
|
+
exports.simulatePointerDevice = simulatePointerDevice;
|
|
10
|
+
var _createRenderer = require("./createRenderer");
|
|
11
|
+
function focusVisible(element) {
|
|
12
|
+
(0, _createRenderer.act)(() => {
|
|
13
|
+
element.blur();
|
|
14
|
+
});
|
|
15
|
+
_createRenderer.fireEvent.keyDown(document.body, {
|
|
16
|
+
key: 'Tab'
|
|
17
|
+
});
|
|
18
|
+
(0, _createRenderer.act)(() => {
|
|
19
|
+
element.focus();
|
|
20
|
+
});
|
|
21
|
+
}
|
|
22
|
+
function simulatePointerDevice() {
|
|
23
|
+
// first focus on a page triggers focus visible until a pointer event
|
|
24
|
+
// has been dispatched
|
|
25
|
+
_createRenderer.fireEvent.pointerDown(document.body);
|
|
26
|
+
}
|
|
27
|
+
function simulateKeyboardDevice() {
|
|
28
|
+
_createRenderer.fireEvent.keyDown(document.body, {
|
|
29
|
+
key: 'TAB'
|
|
30
|
+
});
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
/**
|
|
34
|
+
* See https://issues.chromium.org/issues/40719291 for more details.
|
|
35
|
+
*/
|
|
36
|
+
function programmaticFocusTriggersFocusVisible() {
|
|
37
|
+
try {
|
|
38
|
+
// So far this only applies to Chrome 86 beta which is the only tested browser supporting this pseudo class.
|
|
39
|
+
document.createElement('button').matches(':focus-visible');
|
|
40
|
+
return true;
|
|
41
|
+
} catch (error) {
|
|
42
|
+
return false;
|
|
43
|
+
}
|
|
44
|
+
}
|
package/index.d.ts
ADDED
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
export * from "./components.js";
|
|
2
|
+
export { default as describeConformance } from "./describeConformance.js";
|
|
3
|
+
export * from "./describeConformance.js";
|
|
4
|
+
export { default as createDescribe } from "./createDescribe.js";
|
|
5
|
+
export * from "./createRenderer.js";
|
|
6
|
+
export { default as focusVisible, simulatePointerDevice, simulateKeyboardDevice, programmaticFocusTriggersFocusVisible } from "./focusVisible.js";
|
|
7
|
+
export {} from "./initMatchers.js";
|
|
8
|
+
export * as fireDiscreteEvent from "./fireDiscreteEvent.js";
|
|
9
|
+
export { default as flushMicrotasks } from "./flushMicrotasks.js";
|
|
10
|
+
export { default as reactMajor } from "./reactMajor.js";
|
|
11
|
+
export * from "./env.js";
|
|
12
|
+
/**
|
|
13
|
+
* Set to true if console logs during [lifecycles that are invoked twice in `React.StrictMode`](https://reactjs.org/docs/strict-mode.html#detecting-unexpected-side-effects) are suppressed.
|
|
14
|
+
* Useful for asserting on `console.warn` or `console.error` via `toErrorDev()`.
|
|
15
|
+
* TODO: Refactor to use reactMajor when fixing the React 17 cron test.
|
|
16
|
+
* https://github.com/mui/material-ui/issues/43153
|
|
17
|
+
*/
|
|
18
|
+
export declare const strictModeDoubleLoggingSuppressed: boolean;
|