@mui/internal-test-utils 2.0.18-canary.15 → 2.0.18-canary.17
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/describeConformance.d.mts +0 -18
- package/describeConformance.d.ts +0 -18
- package/describeConformance.js +2 -173
- package/describeConformance.mjs +2 -173
- package/package.json +2 -3
|
@@ -59,7 +59,6 @@ export interface ConformanceOptions {
|
|
|
59
59
|
};
|
|
60
60
|
testCustomVariant?: boolean;
|
|
61
61
|
testVariantProps?: object;
|
|
62
|
-
testLegacyComponentsProp?: boolean | string[];
|
|
63
62
|
slots?: Record<string, SlotTestingOptions>;
|
|
64
63
|
ThemeProvider?: React.ElementType;
|
|
65
64
|
/**
|
|
@@ -123,20 +122,11 @@ declare function testSlotsProp(element: React.ReactElement<{
|
|
|
123
122
|
children: React.ReactNode;
|
|
124
123
|
} & React.RefAttributes<HTMLDivElement>>;
|
|
125
124
|
};
|
|
126
|
-
components?: {
|
|
127
|
-
[x: string]: SlotTestingOptions['testWithComponent'] | keyof React.JSX.IntrinsicElements | React.ForwardRefExoticComponent<{
|
|
128
|
-
children: React.ReactNode;
|
|
129
|
-
} & React.RefAttributes<HTMLDivElement>>;
|
|
130
|
-
};
|
|
131
125
|
slotProps: {
|
|
132
126
|
[x: string]: DataProps;
|
|
133
127
|
};
|
|
134
|
-
componentsProps?: {
|
|
135
|
-
[x: string]: DataProps;
|
|
136
|
-
};
|
|
137
128
|
}>, getOptions: () => ConformanceOptions): void;
|
|
138
129
|
declare function testSlotPropsProp(element: React.ReactElement<{
|
|
139
|
-
componentsProps?: Record<string, DataProps>;
|
|
140
130
|
slotProps: Record<string, DataProps>;
|
|
141
131
|
}>, getOptions: () => ConformanceOptions): void;
|
|
142
132
|
declare function testSlotPropsCallback(element: React.ReactElement<{
|
|
@@ -147,13 +137,6 @@ declare function testSlotPropsCallbackWithPropsAsOwnerState(element: React.React
|
|
|
147
137
|
slotProps: Record<string, (ownerState: Record<string, any>) => DataProps>;
|
|
148
138
|
className: string;
|
|
149
139
|
}>, getOptions: () => ConformanceOptions): void;
|
|
150
|
-
/**
|
|
151
|
-
* MUI components have a `components` prop that allows rendering a different
|
|
152
|
-
* Components from @inheritComponent
|
|
153
|
-
*/
|
|
154
|
-
declare function testComponentsProp(element: React.ReactElement<{
|
|
155
|
-
components?: Record<string, string>;
|
|
156
|
-
} & DataProps>, getOptions: () => ConformanceOptions): void;
|
|
157
140
|
/**
|
|
158
141
|
* MUI theme has a components section that allows specifying default props.
|
|
159
142
|
* Components from @inheritComponent
|
|
@@ -178,7 +161,6 @@ declare function testThemeVariants(element: React.ReactElement<DataProps & {
|
|
|
178
161
|
declare function testThemeCustomPalette(element: React.ReactElement<unknown>, getOptions: () => ConformanceOptions): void;
|
|
179
162
|
declare const fullSuite: {
|
|
180
163
|
componentProp: typeof testComponentProp;
|
|
181
|
-
componentsProp: typeof testComponentsProp;
|
|
182
164
|
mergeClassName: typeof testClassName;
|
|
183
165
|
propsSpread: typeof testPropsSpread;
|
|
184
166
|
refForwarding: typeof describeRef;
|
package/describeConformance.d.ts
CHANGED
|
@@ -59,7 +59,6 @@ export interface ConformanceOptions {
|
|
|
59
59
|
};
|
|
60
60
|
testCustomVariant?: boolean;
|
|
61
61
|
testVariantProps?: object;
|
|
62
|
-
testLegacyComponentsProp?: boolean | string[];
|
|
63
62
|
slots?: Record<string, SlotTestingOptions>;
|
|
64
63
|
ThemeProvider?: React.ElementType;
|
|
65
64
|
/**
|
|
@@ -123,20 +122,11 @@ declare function testSlotsProp(element: React.ReactElement<{
|
|
|
123
122
|
children: React.ReactNode;
|
|
124
123
|
} & React.RefAttributes<HTMLDivElement>>;
|
|
125
124
|
};
|
|
126
|
-
components?: {
|
|
127
|
-
[x: string]: SlotTestingOptions['testWithComponent'] | keyof React.JSX.IntrinsicElements | React.ForwardRefExoticComponent<{
|
|
128
|
-
children: React.ReactNode;
|
|
129
|
-
} & React.RefAttributes<HTMLDivElement>>;
|
|
130
|
-
};
|
|
131
125
|
slotProps: {
|
|
132
126
|
[x: string]: DataProps;
|
|
133
127
|
};
|
|
134
|
-
componentsProps?: {
|
|
135
|
-
[x: string]: DataProps;
|
|
136
|
-
};
|
|
137
128
|
}>, getOptions: () => ConformanceOptions): void;
|
|
138
129
|
declare function testSlotPropsProp(element: React.ReactElement<{
|
|
139
|
-
componentsProps?: Record<string, DataProps>;
|
|
140
130
|
slotProps: Record<string, DataProps>;
|
|
141
131
|
}>, getOptions: () => ConformanceOptions): void;
|
|
142
132
|
declare function testSlotPropsCallback(element: React.ReactElement<{
|
|
@@ -147,13 +137,6 @@ declare function testSlotPropsCallbackWithPropsAsOwnerState(element: React.React
|
|
|
147
137
|
slotProps: Record<string, (ownerState: Record<string, any>) => DataProps>;
|
|
148
138
|
className: string;
|
|
149
139
|
}>, getOptions: () => ConformanceOptions): void;
|
|
150
|
-
/**
|
|
151
|
-
* MUI components have a `components` prop that allows rendering a different
|
|
152
|
-
* Components from @inheritComponent
|
|
153
|
-
*/
|
|
154
|
-
declare function testComponentsProp(element: React.ReactElement<{
|
|
155
|
-
components?: Record<string, string>;
|
|
156
|
-
} & DataProps>, getOptions: () => ConformanceOptions): void;
|
|
157
140
|
/**
|
|
158
141
|
* MUI theme has a components section that allows specifying default props.
|
|
159
142
|
* Components from @inheritComponent
|
|
@@ -178,7 +161,6 @@ declare function testThemeVariants(element: React.ReactElement<DataProps & {
|
|
|
178
161
|
declare function testThemeCustomPalette(element: React.ReactElement<unknown>, getOptions: () => ConformanceOptions): void;
|
|
179
162
|
declare const fullSuite: {
|
|
180
163
|
componentProp: typeof testComponentProp;
|
|
181
|
-
componentsProp: typeof testComponentsProp;
|
|
182
164
|
mergeClassName: typeof testClassName;
|
|
183
165
|
propsSpread: typeof testPropsSpread;
|
|
184
166
|
refForwarding: typeof describeRef;
|
package/describeConformance.js
CHANGED
|
@@ -18,9 +18,6 @@ var _vitest = require("vitest");
|
|
|
18
18
|
var _createDescribe = _interopRequireDefault(require("./createDescribe"));
|
|
19
19
|
var _env = require("./env");
|
|
20
20
|
var _jsxRuntime = require("react/jsx-runtime");
|
|
21
|
-
function capitalize(string) {
|
|
22
|
-
return string.charAt(0).toUpperCase() + string.slice(1);
|
|
23
|
-
}
|
|
24
21
|
/**
|
|
25
22
|
* Glossary
|
|
26
23
|
* - root component:
|
|
@@ -211,8 +208,7 @@ function forEachSlot(slots, callback) {
|
|
|
211
208
|
function testSlotsProp(element, getOptions) {
|
|
212
209
|
const {
|
|
213
210
|
render,
|
|
214
|
-
slots
|
|
215
|
-
testLegacyComponentsProp
|
|
211
|
+
slots
|
|
216
212
|
} = getOptions();
|
|
217
213
|
const CustomComponent = /*#__PURE__*/React.forwardRef(({
|
|
218
214
|
className,
|
|
@@ -274,107 +270,12 @@ function testSlotsProp(element, getOptions) {
|
|
|
274
270
|
}
|
|
275
271
|
});
|
|
276
272
|
}
|
|
277
|
-
|
|
278
|
-
// For testing Material UI components v5, and v6. Likely to be removed in a future major release.
|
|
279
|
-
if (testLegacyComponentsProp === true || Array.isArray(testLegacyComponentsProp) && testLegacyComponentsProp.includes(slotName)) {
|
|
280
|
-
(0, _vitest.it)(`allows overriding the ${slotName} slot with a component using the components.${capitalize(slotName)} prop`, async () => {
|
|
281
|
-
if (!render) {
|
|
282
|
-
throwMissingPropError('render');
|
|
283
|
-
}
|
|
284
|
-
const slotComponent = slotOptions.testWithComponent ?? CustomComponent;
|
|
285
|
-
const components = {
|
|
286
|
-
[capitalize(slotName)]: slotComponent
|
|
287
|
-
};
|
|
288
|
-
const {
|
|
289
|
-
queryByTestId
|
|
290
|
-
} = await render(/*#__PURE__*/React.cloneElement(element, {
|
|
291
|
-
components
|
|
292
|
-
}));
|
|
293
|
-
const renderedElement = queryByTestId('custom');
|
|
294
|
-
(0, _chai.expect)(renderedElement).not.to.equal(null);
|
|
295
|
-
if (slotOptions.expectedClassName) {
|
|
296
|
-
(0, _chai.expect)(renderedElement).to.have.class(slotOptions.expectedClassName);
|
|
297
|
-
}
|
|
298
|
-
});
|
|
299
|
-
(0, _vitest.it)(`prioritizes the 'slots.${slotName}' over components.${capitalize(slotName)} if both are defined`, async () => {
|
|
300
|
-
if (!render) {
|
|
301
|
-
throwMissingPropError('render');
|
|
302
|
-
}
|
|
303
|
-
const ComponentForComponentsProp = /*#__PURE__*/React.forwardRef(({
|
|
304
|
-
children
|
|
305
|
-
}, ref) => {
|
|
306
|
-
const SlotComponent = slotOptions.testWithComponent ?? 'div';
|
|
307
|
-
return /*#__PURE__*/(0, _jsxRuntime.jsx)(SlotComponent, {
|
|
308
|
-
ref: ref,
|
|
309
|
-
"data-testid": "from-components",
|
|
310
|
-
children: children
|
|
311
|
-
});
|
|
312
|
-
});
|
|
313
|
-
if (process.env.NODE_ENV !== "production") ComponentForComponentsProp.displayName = "ComponentForComponentsProp";
|
|
314
|
-
const ComponentForSlotsProp = /*#__PURE__*/React.forwardRef(({
|
|
315
|
-
children
|
|
316
|
-
}, ref) => {
|
|
317
|
-
const SlotComponent = slotOptions.testWithComponent ?? 'div';
|
|
318
|
-
return /*#__PURE__*/(0, _jsxRuntime.jsx)(SlotComponent, {
|
|
319
|
-
ref: ref,
|
|
320
|
-
"data-testid": "from-slots",
|
|
321
|
-
children: children
|
|
322
|
-
});
|
|
323
|
-
});
|
|
324
|
-
if (process.env.NODE_ENV !== "production") ComponentForSlotsProp.displayName = "ComponentForSlotsProp";
|
|
325
|
-
const components = {
|
|
326
|
-
[capitalize(slotName)]: ComponentForComponentsProp
|
|
327
|
-
};
|
|
328
|
-
const slotOverrides = {
|
|
329
|
-
[slotName]: ComponentForSlotsProp
|
|
330
|
-
};
|
|
331
|
-
const {
|
|
332
|
-
queryByTestId
|
|
333
|
-
} = await render(/*#__PURE__*/React.cloneElement(element, {
|
|
334
|
-
components,
|
|
335
|
-
slots: slotOverrides
|
|
336
|
-
}));
|
|
337
|
-
(0, _chai.expect)(queryByTestId('from-slots')).not.to.equal(null);
|
|
338
|
-
(0, _chai.expect)(queryByTestId('from-components')).to.equal(null);
|
|
339
|
-
});
|
|
340
|
-
if (slotOptions.testWithElement !== null) {
|
|
341
|
-
(0, _vitest.it)(`allows overriding the ${slotName} slot with an element using the components.${capitalize(slotName)} prop`, async () => {
|
|
342
|
-
if (!render) {
|
|
343
|
-
throwMissingPropError('render');
|
|
344
|
-
}
|
|
345
|
-
const slotElement = slotOptions.testWithElement ?? 'i';
|
|
346
|
-
const components = {
|
|
347
|
-
[capitalize(slotName)]: slotElement
|
|
348
|
-
};
|
|
349
|
-
const componentsProps = {
|
|
350
|
-
[slotName]: {
|
|
351
|
-
'data-testid': 'customized'
|
|
352
|
-
}
|
|
353
|
-
};
|
|
354
|
-
const {
|
|
355
|
-
queryByTestId
|
|
356
|
-
} = await render(/*#__PURE__*/React.cloneElement(element, {
|
|
357
|
-
components,
|
|
358
|
-
componentsProps
|
|
359
|
-
}));
|
|
360
|
-
const renderedElement = queryByTestId('customized');
|
|
361
|
-
(0, _chai.expect)(renderedElement).not.to.equal(null);
|
|
362
|
-
if (typeof slotElement === 'string') {
|
|
363
|
-
(0, _chai.expect)(renderedElement.nodeName.toLowerCase()).to.equal(slotElement);
|
|
364
|
-
}
|
|
365
|
-
if (slotOptions.expectedClassName) {
|
|
366
|
-
(0, _chai.expect)(renderedElement).to.have.class(slotOptions.expectedClassName);
|
|
367
|
-
}
|
|
368
|
-
});
|
|
369
|
-
}
|
|
370
|
-
}
|
|
371
273
|
});
|
|
372
274
|
}
|
|
373
275
|
function testSlotPropsProp(element, getOptions) {
|
|
374
276
|
const {
|
|
375
277
|
render,
|
|
376
|
-
slots
|
|
377
|
-
testLegacyComponentsProp
|
|
278
|
+
slots
|
|
378
279
|
} = getOptions();
|
|
379
280
|
if (!render) {
|
|
380
281
|
throwMissingPropError('render');
|
|
@@ -414,48 +315,6 @@ function testSlotPropsProp(element, getOptions) {
|
|
|
414
315
|
(0, _chai.expect)(getByTestId('custom')).to.have.class(slotProps[slotName].className);
|
|
415
316
|
});
|
|
416
317
|
}
|
|
417
|
-
if (testLegacyComponentsProp === true || Array.isArray(testLegacyComponentsProp) && testLegacyComponentsProp.includes(slotName)) {
|
|
418
|
-
(0, _vitest.it)(`sets custom properties on the ${slotName} slot's element with the componentsProps.${slotName} prop`, async () => {
|
|
419
|
-
const componentsProps = {
|
|
420
|
-
[slotName]: {
|
|
421
|
-
'data-testid': 'custom'
|
|
422
|
-
}
|
|
423
|
-
};
|
|
424
|
-
const {
|
|
425
|
-
queryByTestId
|
|
426
|
-
} = await render(/*#__PURE__*/React.cloneElement(element, {
|
|
427
|
-
componentsProps
|
|
428
|
-
}));
|
|
429
|
-
const slotComponent = queryByTestId('custom');
|
|
430
|
-
(0, _chai.expect)(slotComponent).not.to.equal(null);
|
|
431
|
-
if (slotOptions.expectedClassName) {
|
|
432
|
-
(0, _chai.expect)(slotComponent).to.have.class(slotOptions.expectedClassName);
|
|
433
|
-
}
|
|
434
|
-
});
|
|
435
|
-
(0, _vitest.it)(`prioritizes the 'slotProps.${slotName}' over componentsProps.${slotName} if both are defined`, async () => {
|
|
436
|
-
const componentsProps = {
|
|
437
|
-
[slotName]: {
|
|
438
|
-
'data-testid': 'custom',
|
|
439
|
-
'data-from-components-props': 'true'
|
|
440
|
-
}
|
|
441
|
-
};
|
|
442
|
-
const slotProps = {
|
|
443
|
-
[slotName]: {
|
|
444
|
-
'data-testid': 'custom',
|
|
445
|
-
'data-from-slot-props': 'true'
|
|
446
|
-
}
|
|
447
|
-
};
|
|
448
|
-
const {
|
|
449
|
-
queryByTestId
|
|
450
|
-
} = await render(/*#__PURE__*/React.cloneElement(element, {
|
|
451
|
-
componentsProps,
|
|
452
|
-
slotProps
|
|
453
|
-
}));
|
|
454
|
-
const slotComponent = queryByTestId('custom');
|
|
455
|
-
(0, _chai.expect)(slotComponent).to.have.attribute('data-from-slot-props', 'true');
|
|
456
|
-
(0, _chai.expect)(slotComponent).not.to.have.attribute('data-from-components-props');
|
|
457
|
-
});
|
|
458
|
-
}
|
|
459
318
|
});
|
|
460
319
|
}
|
|
461
320
|
function testSlotPropsCallback(element, getOptions) {
|
|
@@ -513,35 +372,6 @@ function testSlotPropsCallbackWithPropsAsOwnerState(element, getOptions) {
|
|
|
513
372
|
});
|
|
514
373
|
}
|
|
515
374
|
|
|
516
|
-
/**
|
|
517
|
-
* MUI components have a `components` prop that allows rendering a different
|
|
518
|
-
* Components from @inheritComponent
|
|
519
|
-
*/
|
|
520
|
-
function testComponentsProp(element, getOptions) {
|
|
521
|
-
(0, _vitest.describe)('prop components:', () => {
|
|
522
|
-
(0, _vitest.it)('can render another root component with the `components` prop', async () => {
|
|
523
|
-
const {
|
|
524
|
-
render,
|
|
525
|
-
testComponentsRootPropWith: component = 'em'
|
|
526
|
-
} = getOptions();
|
|
527
|
-
if (!render) {
|
|
528
|
-
throwMissingPropError('render');
|
|
529
|
-
}
|
|
530
|
-
const testId = randomStringValue();
|
|
531
|
-
const {
|
|
532
|
-
getByTestId
|
|
533
|
-
} = await render(/*#__PURE__*/React.cloneElement(element, {
|
|
534
|
-
components: {
|
|
535
|
-
Root: component
|
|
536
|
-
},
|
|
537
|
-
'data-testid': testId
|
|
538
|
-
}));
|
|
539
|
-
(0, _chai.expect)(getByTestId(testId)).not.to.equal(null);
|
|
540
|
-
(0, _chai.expect)(getByTestId(testId).nodeName.toLowerCase()).to.eq(component);
|
|
541
|
-
});
|
|
542
|
-
});
|
|
543
|
-
}
|
|
544
|
-
|
|
545
375
|
/**
|
|
546
376
|
* MUI theme has a components section that allows specifying default props.
|
|
547
377
|
* Components from @inheritComponent
|
|
@@ -977,7 +807,6 @@ function testThemeCustomPalette(element, getOptions) {
|
|
|
977
807
|
}
|
|
978
808
|
const fullSuite = {
|
|
979
809
|
componentProp: testComponentProp,
|
|
980
|
-
componentsProp: testComponentsProp,
|
|
981
810
|
mergeClassName: testClassName,
|
|
982
811
|
propsSpread: testPropsSpread,
|
|
983
812
|
refForwarding: describeRef,
|
package/describeConformance.mjs
CHANGED
|
@@ -4,9 +4,6 @@ import { describe, it, afterAll, afterEach, beforeEach } from 'vitest';
|
|
|
4
4
|
import createDescribe from "./createDescribe.mjs";
|
|
5
5
|
import { isJsdom } from "./env.mjs";
|
|
6
6
|
import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
|
|
7
|
-
function capitalize(string) {
|
|
8
|
-
return string.charAt(0).toUpperCase() + string.slice(1);
|
|
9
|
-
}
|
|
10
7
|
/**
|
|
11
8
|
* Glossary
|
|
12
9
|
* - root component:
|
|
@@ -197,8 +194,7 @@ function forEachSlot(slots, callback) {
|
|
|
197
194
|
function testSlotsProp(element, getOptions) {
|
|
198
195
|
const {
|
|
199
196
|
render,
|
|
200
|
-
slots
|
|
201
|
-
testLegacyComponentsProp
|
|
197
|
+
slots
|
|
202
198
|
} = getOptions();
|
|
203
199
|
const CustomComponent = /*#__PURE__*/React.forwardRef(({
|
|
204
200
|
className,
|
|
@@ -260,107 +256,12 @@ function testSlotsProp(element, getOptions) {
|
|
|
260
256
|
}
|
|
261
257
|
});
|
|
262
258
|
}
|
|
263
|
-
|
|
264
|
-
// For testing Material UI components v5, and v6. Likely to be removed in a future major release.
|
|
265
|
-
if (testLegacyComponentsProp === true || Array.isArray(testLegacyComponentsProp) && testLegacyComponentsProp.includes(slotName)) {
|
|
266
|
-
it(`allows overriding the ${slotName} slot with a component using the components.${capitalize(slotName)} prop`, async () => {
|
|
267
|
-
if (!render) {
|
|
268
|
-
throwMissingPropError('render');
|
|
269
|
-
}
|
|
270
|
-
const slotComponent = slotOptions.testWithComponent ?? CustomComponent;
|
|
271
|
-
const components = {
|
|
272
|
-
[capitalize(slotName)]: slotComponent
|
|
273
|
-
};
|
|
274
|
-
const {
|
|
275
|
-
queryByTestId
|
|
276
|
-
} = await render(/*#__PURE__*/React.cloneElement(element, {
|
|
277
|
-
components
|
|
278
|
-
}));
|
|
279
|
-
const renderedElement = queryByTestId('custom');
|
|
280
|
-
expect(renderedElement).not.to.equal(null);
|
|
281
|
-
if (slotOptions.expectedClassName) {
|
|
282
|
-
expect(renderedElement).to.have.class(slotOptions.expectedClassName);
|
|
283
|
-
}
|
|
284
|
-
});
|
|
285
|
-
it(`prioritizes the 'slots.${slotName}' over components.${capitalize(slotName)} if both are defined`, async () => {
|
|
286
|
-
if (!render) {
|
|
287
|
-
throwMissingPropError('render');
|
|
288
|
-
}
|
|
289
|
-
const ComponentForComponentsProp = /*#__PURE__*/React.forwardRef(({
|
|
290
|
-
children
|
|
291
|
-
}, ref) => {
|
|
292
|
-
const SlotComponent = slotOptions.testWithComponent ?? 'div';
|
|
293
|
-
return /*#__PURE__*/_jsx(SlotComponent, {
|
|
294
|
-
ref: ref,
|
|
295
|
-
"data-testid": "from-components",
|
|
296
|
-
children: children
|
|
297
|
-
});
|
|
298
|
-
});
|
|
299
|
-
if (process.env.NODE_ENV !== "production") ComponentForComponentsProp.displayName = "ComponentForComponentsProp";
|
|
300
|
-
const ComponentForSlotsProp = /*#__PURE__*/React.forwardRef(({
|
|
301
|
-
children
|
|
302
|
-
}, ref) => {
|
|
303
|
-
const SlotComponent = slotOptions.testWithComponent ?? 'div';
|
|
304
|
-
return /*#__PURE__*/_jsx(SlotComponent, {
|
|
305
|
-
ref: ref,
|
|
306
|
-
"data-testid": "from-slots",
|
|
307
|
-
children: children
|
|
308
|
-
});
|
|
309
|
-
});
|
|
310
|
-
if (process.env.NODE_ENV !== "production") ComponentForSlotsProp.displayName = "ComponentForSlotsProp";
|
|
311
|
-
const components = {
|
|
312
|
-
[capitalize(slotName)]: ComponentForComponentsProp
|
|
313
|
-
};
|
|
314
|
-
const slotOverrides = {
|
|
315
|
-
[slotName]: ComponentForSlotsProp
|
|
316
|
-
};
|
|
317
|
-
const {
|
|
318
|
-
queryByTestId
|
|
319
|
-
} = await render(/*#__PURE__*/React.cloneElement(element, {
|
|
320
|
-
components,
|
|
321
|
-
slots: slotOverrides
|
|
322
|
-
}));
|
|
323
|
-
expect(queryByTestId('from-slots')).not.to.equal(null);
|
|
324
|
-
expect(queryByTestId('from-components')).to.equal(null);
|
|
325
|
-
});
|
|
326
|
-
if (slotOptions.testWithElement !== null) {
|
|
327
|
-
it(`allows overriding the ${slotName} slot with an element using the components.${capitalize(slotName)} prop`, async () => {
|
|
328
|
-
if (!render) {
|
|
329
|
-
throwMissingPropError('render');
|
|
330
|
-
}
|
|
331
|
-
const slotElement = slotOptions.testWithElement ?? 'i';
|
|
332
|
-
const components = {
|
|
333
|
-
[capitalize(slotName)]: slotElement
|
|
334
|
-
};
|
|
335
|
-
const componentsProps = {
|
|
336
|
-
[slotName]: {
|
|
337
|
-
'data-testid': 'customized'
|
|
338
|
-
}
|
|
339
|
-
};
|
|
340
|
-
const {
|
|
341
|
-
queryByTestId
|
|
342
|
-
} = await render(/*#__PURE__*/React.cloneElement(element, {
|
|
343
|
-
components,
|
|
344
|
-
componentsProps
|
|
345
|
-
}));
|
|
346
|
-
const renderedElement = queryByTestId('customized');
|
|
347
|
-
expect(renderedElement).not.to.equal(null);
|
|
348
|
-
if (typeof slotElement === 'string') {
|
|
349
|
-
expect(renderedElement.nodeName.toLowerCase()).to.equal(slotElement);
|
|
350
|
-
}
|
|
351
|
-
if (slotOptions.expectedClassName) {
|
|
352
|
-
expect(renderedElement).to.have.class(slotOptions.expectedClassName);
|
|
353
|
-
}
|
|
354
|
-
});
|
|
355
|
-
}
|
|
356
|
-
}
|
|
357
259
|
});
|
|
358
260
|
}
|
|
359
261
|
function testSlotPropsProp(element, getOptions) {
|
|
360
262
|
const {
|
|
361
263
|
render,
|
|
362
|
-
slots
|
|
363
|
-
testLegacyComponentsProp
|
|
264
|
+
slots
|
|
364
265
|
} = getOptions();
|
|
365
266
|
if (!render) {
|
|
366
267
|
throwMissingPropError('render');
|
|
@@ -400,48 +301,6 @@ function testSlotPropsProp(element, getOptions) {
|
|
|
400
301
|
expect(getByTestId('custom')).to.have.class(slotProps[slotName].className);
|
|
401
302
|
});
|
|
402
303
|
}
|
|
403
|
-
if (testLegacyComponentsProp === true || Array.isArray(testLegacyComponentsProp) && testLegacyComponentsProp.includes(slotName)) {
|
|
404
|
-
it(`sets custom properties on the ${slotName} slot's element with the componentsProps.${slotName} prop`, async () => {
|
|
405
|
-
const componentsProps = {
|
|
406
|
-
[slotName]: {
|
|
407
|
-
'data-testid': 'custom'
|
|
408
|
-
}
|
|
409
|
-
};
|
|
410
|
-
const {
|
|
411
|
-
queryByTestId
|
|
412
|
-
} = await render(/*#__PURE__*/React.cloneElement(element, {
|
|
413
|
-
componentsProps
|
|
414
|
-
}));
|
|
415
|
-
const slotComponent = queryByTestId('custom');
|
|
416
|
-
expect(slotComponent).not.to.equal(null);
|
|
417
|
-
if (slotOptions.expectedClassName) {
|
|
418
|
-
expect(slotComponent).to.have.class(slotOptions.expectedClassName);
|
|
419
|
-
}
|
|
420
|
-
});
|
|
421
|
-
it(`prioritizes the 'slotProps.${slotName}' over componentsProps.${slotName} if both are defined`, async () => {
|
|
422
|
-
const componentsProps = {
|
|
423
|
-
[slotName]: {
|
|
424
|
-
'data-testid': 'custom',
|
|
425
|
-
'data-from-components-props': 'true'
|
|
426
|
-
}
|
|
427
|
-
};
|
|
428
|
-
const slotProps = {
|
|
429
|
-
[slotName]: {
|
|
430
|
-
'data-testid': 'custom',
|
|
431
|
-
'data-from-slot-props': 'true'
|
|
432
|
-
}
|
|
433
|
-
};
|
|
434
|
-
const {
|
|
435
|
-
queryByTestId
|
|
436
|
-
} = await render(/*#__PURE__*/React.cloneElement(element, {
|
|
437
|
-
componentsProps,
|
|
438
|
-
slotProps
|
|
439
|
-
}));
|
|
440
|
-
const slotComponent = queryByTestId('custom');
|
|
441
|
-
expect(slotComponent).to.have.attribute('data-from-slot-props', 'true');
|
|
442
|
-
expect(slotComponent).not.to.have.attribute('data-from-components-props');
|
|
443
|
-
});
|
|
444
|
-
}
|
|
445
304
|
});
|
|
446
305
|
}
|
|
447
306
|
function testSlotPropsCallback(element, getOptions) {
|
|
@@ -499,35 +358,6 @@ function testSlotPropsCallbackWithPropsAsOwnerState(element, getOptions) {
|
|
|
499
358
|
});
|
|
500
359
|
}
|
|
501
360
|
|
|
502
|
-
/**
|
|
503
|
-
* MUI components have a `components` prop that allows rendering a different
|
|
504
|
-
* Components from @inheritComponent
|
|
505
|
-
*/
|
|
506
|
-
function testComponentsProp(element, getOptions) {
|
|
507
|
-
describe('prop components:', () => {
|
|
508
|
-
it('can render another root component with the `components` prop', async () => {
|
|
509
|
-
const {
|
|
510
|
-
render,
|
|
511
|
-
testComponentsRootPropWith: component = 'em'
|
|
512
|
-
} = getOptions();
|
|
513
|
-
if (!render) {
|
|
514
|
-
throwMissingPropError('render');
|
|
515
|
-
}
|
|
516
|
-
const testId = randomStringValue();
|
|
517
|
-
const {
|
|
518
|
-
getByTestId
|
|
519
|
-
} = await render(/*#__PURE__*/React.cloneElement(element, {
|
|
520
|
-
components: {
|
|
521
|
-
Root: component
|
|
522
|
-
},
|
|
523
|
-
'data-testid': testId
|
|
524
|
-
}));
|
|
525
|
-
expect(getByTestId(testId)).not.to.equal(null);
|
|
526
|
-
expect(getByTestId(testId).nodeName.toLowerCase()).to.eq(component);
|
|
527
|
-
});
|
|
528
|
-
});
|
|
529
|
-
}
|
|
530
|
-
|
|
531
361
|
/**
|
|
532
362
|
* MUI theme has a components section that allows specifying default props.
|
|
533
363
|
* Components from @inheritComponent
|
|
@@ -963,7 +793,6 @@ function testThemeCustomPalette(element, getOptions) {
|
|
|
963
793
|
}
|
|
964
794
|
const fullSuite = {
|
|
965
795
|
componentProp: testComponentProp,
|
|
966
|
-
componentsProp: testComponentsProp,
|
|
967
796
|
mergeClassName: testClassName,
|
|
968
797
|
propsSpread: testPropsSpread,
|
|
969
798
|
refForwarding: describeRef,
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@mui/internal-test-utils",
|
|
3
|
-
"version": "2.0.18-canary.
|
|
3
|
+
"version": "2.0.18-canary.17",
|
|
4
4
|
"author": "MUI Team",
|
|
5
5
|
"description": "Utilities for MUI tests. This is an internal package not meant for general use.",
|
|
6
6
|
"repository": {
|
|
@@ -19,7 +19,6 @@
|
|
|
19
19
|
"dom-accessibility-api": "^0.7.1",
|
|
20
20
|
"es-toolkit": "^1.45.1",
|
|
21
21
|
"format-util": "^1.0.5",
|
|
22
|
-
"jsdom": "^28.1.0",
|
|
23
22
|
"prop-types": "^15.8.1",
|
|
24
23
|
"vitest-fail-on-console": "^0.10.1"
|
|
25
24
|
},
|
|
@@ -160,5 +159,5 @@
|
|
|
160
159
|
},
|
|
161
160
|
"main": "./index.js",
|
|
162
161
|
"types": "./index.d.ts",
|
|
163
|
-
"gitSha": "
|
|
162
|
+
"gitSha": "530ec94f97bfe64ae018a9fd8ff0c326cbd61298"
|
|
164
163
|
}
|