@mui/internal-test-utils 1.0.21 → 1.0.23
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/build/.tsbuildinfo +1 -1
- package/build/chaiPlugin.js +17 -7
- package/build/chaiPlugin.js.map +1 -1
- package/build/components.js +17 -7
- package/build/components.js.map +1 -1
- package/build/createRenderer.js +17 -7
- package/build/createRenderer.js.map +1 -1
- package/build/createRenderer.test.js +17 -7
- package/build/createRenderer.test.js.map +1 -1
- package/build/describeConformance.d.ts +64 -14
- package/build/describeConformance.d.ts.map +1 -1
- package/build/describeConformance.js +42 -8
- package/build/describeConformance.js.map +1 -1
- package/build/index.js +17 -7
- package/build/index.js.map +1 -1
- package/build/init.js +17 -7
- package/build/init.js.map +1 -1
- package/build/initPlaywrightMatchers.js +17 -7
- package/build/initPlaywrightMatchers.js.map +1 -1
- package/build/mochaHooks.d.ts.map +1 -1
- package/build/mochaHooks.test.js +17 -7
- package/build/mochaHooks.test.js.map +1 -1
- package/build/reactMajor.js +17 -7
- package/build/reactMajor.js.map +1 -1
- package/build/setupVitest.js +17 -7
- package/build/setupVitest.js.map +1 -1
- package/package.json +11 -11
- package/src/describeConformance.tsx +123 -15
|
@@ -8,6 +8,10 @@ function capitalize(string: string): string {
|
|
|
8
8
|
return string.charAt(0).toUpperCase() + string.slice(1);
|
|
9
9
|
}
|
|
10
10
|
|
|
11
|
+
interface DataProps {
|
|
12
|
+
[key: `data-${string}`]: string;
|
|
13
|
+
}
|
|
14
|
+
|
|
11
15
|
export interface SlotTestingOptions {
|
|
12
16
|
/**
|
|
13
17
|
* A custom React component to test if the receiving props are correct.
|
|
@@ -41,7 +45,7 @@ export interface ConformanceOptions {
|
|
|
41
45
|
refInstanceof: any;
|
|
42
46
|
after?: () => void;
|
|
43
47
|
inheritComponent?: React.ElementType;
|
|
44
|
-
render: (node: React.ReactElement<
|
|
48
|
+
render: (node: React.ReactElement<DataProps>) => MuiRenderResult | Promise<MuiRenderResult>;
|
|
45
49
|
only?: Array<keyof typeof fullSuite>;
|
|
46
50
|
skip?: Array<keyof typeof fullSuite | 'classesRoot'>;
|
|
47
51
|
testComponentsRootPropWith?: string;
|
|
@@ -95,7 +99,11 @@ function throwMissingPropError(field: string): never {
|
|
|
95
99
|
* the root component.
|
|
96
100
|
*/
|
|
97
101
|
export function testClassName(
|
|
98
|
-
element: React.ReactElement<
|
|
102
|
+
element: React.ReactElement<
|
|
103
|
+
DataProps & {
|
|
104
|
+
className: string;
|
|
105
|
+
}
|
|
106
|
+
>,
|
|
99
107
|
getOptions: () => ConformanceOptions,
|
|
100
108
|
) {
|
|
101
109
|
it('applies the className to the root component', async () => {
|
|
@@ -121,7 +129,12 @@ export function testClassName(
|
|
|
121
129
|
* Component from @inheritComponent
|
|
122
130
|
*/
|
|
123
131
|
export function testComponentProp(
|
|
124
|
-
element: React.ReactElement<
|
|
132
|
+
element: React.ReactElement<
|
|
133
|
+
DataProps & {
|
|
134
|
+
className: string;
|
|
135
|
+
component?: string | React.ElementType;
|
|
136
|
+
}
|
|
137
|
+
>,
|
|
125
138
|
getOptions: () => ConformanceOptions,
|
|
126
139
|
) {
|
|
127
140
|
describe('prop: component', () => {
|
|
@@ -157,7 +170,13 @@ export function testComponentProp(
|
|
|
157
170
|
* MUI components spread additional props to its root.
|
|
158
171
|
*/
|
|
159
172
|
export function testPropsSpread(
|
|
160
|
-
element: React.ReactElement<
|
|
173
|
+
element: React.ReactElement<
|
|
174
|
+
DataProps & {
|
|
175
|
+
className: string;
|
|
176
|
+
component: string | React.ElementType;
|
|
177
|
+
}
|
|
178
|
+
>,
|
|
179
|
+
|
|
161
180
|
getOptions: () => ConformanceOptions,
|
|
162
181
|
) {
|
|
163
182
|
it(`spreads props to the root component`, async () => {
|
|
@@ -187,7 +206,9 @@ export function testPropsSpread(
|
|
|
187
206
|
* components that forward their ref and attach it to a host component.
|
|
188
207
|
*/
|
|
189
208
|
export function describeRef(
|
|
190
|
-
element: React.ReactElement<
|
|
209
|
+
element: React.ReactElement<{
|
|
210
|
+
ref: React.RefObject<any>;
|
|
211
|
+
}>,
|
|
191
212
|
getOptions: () => ConformanceOptions,
|
|
192
213
|
) {
|
|
193
214
|
describe('ref', () => {
|
|
@@ -212,7 +233,10 @@ export function describeRef(
|
|
|
212
233
|
* Tests that the root component has the root class
|
|
213
234
|
*/
|
|
214
235
|
export function testRootClass(
|
|
215
|
-
element: React.ReactElement<
|
|
236
|
+
element: React.ReactElement<{
|
|
237
|
+
className: string;
|
|
238
|
+
classes: Record<string, string>;
|
|
239
|
+
}>,
|
|
216
240
|
getOptions: () => ConformanceOptions,
|
|
217
241
|
) {
|
|
218
242
|
it('applies the root class to the root component if it has this class', async () => {
|
|
@@ -264,7 +288,39 @@ function forEachSlot(
|
|
|
264
288
|
});
|
|
265
289
|
}
|
|
266
290
|
|
|
267
|
-
function testSlotsProp(
|
|
291
|
+
function testSlotsProp(
|
|
292
|
+
element: React.ReactElement<{
|
|
293
|
+
className: string;
|
|
294
|
+
classes: Record<string, string>;
|
|
295
|
+
slots: {
|
|
296
|
+
[x: string]:
|
|
297
|
+
| SlotTestingOptions['testWithComponent']
|
|
298
|
+
| keyof React.JSX.IntrinsicElements
|
|
299
|
+
| React.ForwardRefExoticComponent<
|
|
300
|
+
{
|
|
301
|
+
children: React.ReactNode;
|
|
302
|
+
} & React.RefAttributes<HTMLDivElement>
|
|
303
|
+
>;
|
|
304
|
+
};
|
|
305
|
+
components?: {
|
|
306
|
+
[x: string]:
|
|
307
|
+
| SlotTestingOptions['testWithComponent']
|
|
308
|
+
| keyof React.JSX.IntrinsicElements
|
|
309
|
+
| React.ForwardRefExoticComponent<
|
|
310
|
+
{
|
|
311
|
+
children: React.ReactNode;
|
|
312
|
+
} & React.RefAttributes<HTMLDivElement>
|
|
313
|
+
>;
|
|
314
|
+
};
|
|
315
|
+
slotProps: {
|
|
316
|
+
[x: string]: DataProps;
|
|
317
|
+
};
|
|
318
|
+
componentsProps?: {
|
|
319
|
+
[x: string]: DataProps;
|
|
320
|
+
};
|
|
321
|
+
}>,
|
|
322
|
+
getOptions: () => ConformanceOptions,
|
|
323
|
+
) {
|
|
268
324
|
const { render, slots, testLegacyComponentsProp } = getOptions();
|
|
269
325
|
|
|
270
326
|
const CustomComponent = React.forwardRef<
|
|
@@ -439,7 +495,13 @@ function testSlotsProp(element: React.ReactElement<any>, getOptions: () => Confo
|
|
|
439
495
|
});
|
|
440
496
|
}
|
|
441
497
|
|
|
442
|
-
function testSlotPropsProp(
|
|
498
|
+
function testSlotPropsProp(
|
|
499
|
+
element: React.ReactElement<{
|
|
500
|
+
componentsProps?: Record<string, DataProps>;
|
|
501
|
+
slotProps: Record<string, DataProps>;
|
|
502
|
+
}>,
|
|
503
|
+
getOptions: () => ConformanceOptions,
|
|
504
|
+
) {
|
|
443
505
|
const { render, slots, testLegacyComponentsProp } = getOptions();
|
|
444
506
|
|
|
445
507
|
if (!render) {
|
|
@@ -523,7 +585,10 @@ function testSlotPropsProp(element: React.ReactElement<any>, getOptions: () => C
|
|
|
523
585
|
}
|
|
524
586
|
|
|
525
587
|
function testSlotPropsCallback(
|
|
526
|
-
element: React.ReactElement<
|
|
588
|
+
element: React.ReactElement<{
|
|
589
|
+
slotProps: Record<string, () => DataProps>;
|
|
590
|
+
className: string;
|
|
591
|
+
}>,
|
|
527
592
|
getOptions: () => ConformanceOptions,
|
|
528
593
|
) {
|
|
529
594
|
const { render, slots } = getOptions();
|
|
@@ -534,6 +599,36 @@ function testSlotPropsCallback(
|
|
|
534
599
|
|
|
535
600
|
forEachSlot(slots, (slotName) => {
|
|
536
601
|
it(`sets custom properties on the ${slotName} slot's element with the slotProps.${slotName} callback`, async () => {
|
|
602
|
+
const slotProps = {
|
|
603
|
+
[slotName]: () => ({
|
|
604
|
+
'data-testid': 'custom',
|
|
605
|
+
}),
|
|
606
|
+
};
|
|
607
|
+
|
|
608
|
+
const { queryByTestId } = await render(
|
|
609
|
+
React.cloneElement(element, { slotProps, className: 'custom' }),
|
|
610
|
+
);
|
|
611
|
+
const slotComponent = queryByTestId('custom');
|
|
612
|
+
expect(slotComponent).not.to.equal(null);
|
|
613
|
+
});
|
|
614
|
+
});
|
|
615
|
+
}
|
|
616
|
+
|
|
617
|
+
function testSlotPropsCallbackWithPropsAsOwnerState(
|
|
618
|
+
element: React.ReactElement<{
|
|
619
|
+
slotProps: Record<string, (ownerState: Record<string, any>) => DataProps>;
|
|
620
|
+
className: string;
|
|
621
|
+
}>,
|
|
622
|
+
getOptions: () => ConformanceOptions,
|
|
623
|
+
) {
|
|
624
|
+
const { render, slots } = getOptions();
|
|
625
|
+
|
|
626
|
+
if (!render) {
|
|
627
|
+
throwMissingPropError('render');
|
|
628
|
+
}
|
|
629
|
+
|
|
630
|
+
forEachSlot(slots, (slotName) => {
|
|
631
|
+
it(`sets custom properties on the ${slotName} slot's element with the slotProps.${slotName} callback using the ownerState`, async () => {
|
|
537
632
|
const slotProps = {
|
|
538
633
|
[slotName]: (ownerState: Record<string, any>) => ({
|
|
539
634
|
'data-testid': ownerState.className,
|
|
@@ -554,7 +649,11 @@ function testSlotPropsCallback(
|
|
|
554
649
|
* Components from @inheritComponent
|
|
555
650
|
*/
|
|
556
651
|
function testComponentsProp(
|
|
557
|
-
element: React.ReactElement<
|
|
652
|
+
element: React.ReactElement<
|
|
653
|
+
{
|
|
654
|
+
components?: Record<string, string>;
|
|
655
|
+
} & DataProps
|
|
656
|
+
>,
|
|
558
657
|
getOptions: () => ConformanceOptions,
|
|
559
658
|
) {
|
|
560
659
|
describe('prop components:', () => {
|
|
@@ -580,7 +679,7 @@ function testComponentsProp(
|
|
|
580
679
|
* Components from @inheritComponent
|
|
581
680
|
*/
|
|
582
681
|
function testThemeDefaultProps(
|
|
583
|
-
element: React.ReactElement<
|
|
682
|
+
element: React.ReactElement<unknown>,
|
|
584
683
|
getOptions: () => ConformanceOptions,
|
|
585
684
|
) {
|
|
586
685
|
describe('theme default components:', () => {
|
|
@@ -664,7 +763,7 @@ function testThemeDefaultProps(
|
|
|
664
763
|
* Components from @inheritComponent
|
|
665
764
|
*/
|
|
666
765
|
function testThemeStyleOverrides(
|
|
667
|
-
element: React.ReactElement<
|
|
766
|
+
element: React.ReactElement<unknown>,
|
|
668
767
|
getOptions: () => ConformanceOptions,
|
|
669
768
|
) {
|
|
670
769
|
describe('theme style overrides:', () => {
|
|
@@ -916,7 +1015,10 @@ function testThemeStyleOverrides(
|
|
|
916
1015
|
* MUI theme has a components section that allows specifying custom variants.
|
|
917
1016
|
* Components from @inheritComponent
|
|
918
1017
|
*/
|
|
919
|
-
function testThemeVariants(
|
|
1018
|
+
function testThemeVariants(
|
|
1019
|
+
element: React.ReactElement<DataProps & { variant: string }>,
|
|
1020
|
+
getOptions: () => ConformanceOptions,
|
|
1021
|
+
) {
|
|
920
1022
|
describe('theme variants:', () => {
|
|
921
1023
|
it("respect theme's variants", async function test(t = {}) {
|
|
922
1024
|
if (/jsdom/.test(window.navigator.userAgent)) {
|
|
@@ -1026,7 +1128,7 @@ function testThemeVariants(element: React.ReactElement<any>, getOptions: () => C
|
|
|
1026
1128
|
* The components that iterate over the palette via `variants` should be able to render with or without applying the custom palette styles.
|
|
1027
1129
|
*/
|
|
1028
1130
|
function testThemeCustomPalette(
|
|
1029
|
-
element: React.ReactElement<
|
|
1131
|
+
element: React.ReactElement<unknown>,
|
|
1030
1132
|
getOptions: () => ConformanceOptions,
|
|
1031
1133
|
) {
|
|
1032
1134
|
describe('theme extended palette:', () => {
|
|
@@ -1068,6 +1170,7 @@ const fullSuite = {
|
|
|
1068
1170
|
rootClass: testRootClass,
|
|
1069
1171
|
slotPropsProp: testSlotPropsProp,
|
|
1070
1172
|
slotPropsCallback: testSlotPropsCallback,
|
|
1173
|
+
slotPropsCallbackWithPropsAsOwnerState: testSlotPropsCallbackWithPropsAsOwnerState,
|
|
1071
1174
|
slotsProp: testSlotsProp,
|
|
1072
1175
|
themeDefaultProps: testThemeDefaultProps,
|
|
1073
1176
|
themeStyleOverrides: testThemeStyleOverrides,
|
|
@@ -1120,7 +1223,12 @@ function describeConformance(
|
|
|
1120
1223
|
(testKey) => only.includes(testKey) && !skip.includes(testKey as keyof typeof fullSuite),
|
|
1121
1224
|
) as (keyof typeof fullSuite)[];
|
|
1122
1225
|
|
|
1123
|
-
const slotBasedTests = [
|
|
1226
|
+
const slotBasedTests = [
|
|
1227
|
+
'slotsProp',
|
|
1228
|
+
'slotPropsProp',
|
|
1229
|
+
'slotPropsCallback',
|
|
1230
|
+
'slotPropsCallbackWithPropsAsOwnerState',
|
|
1231
|
+
];
|
|
1124
1232
|
|
|
1125
1233
|
if (!slots) {
|
|
1126
1234
|
// if `slots` are not defined, do not run tests that depend on them
|