Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[test] Do not enforce the presence of ownerState.className in describeConformance #44479

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
35 changes: 34 additions & 1 deletion packages-internal/test-utils/src/describeConformance.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -534,6 +534,33 @@ function testSlotPropsCallback(

forEachSlot(slots, (slotName) => {
it(`sets custom properties on the ${slotName} slot's element with the slotProps.${slotName} callback`, async () => {
const slotProps = {
[slotName]: () => ({
'data-testid': 'custom',
}),
};

const { queryByTestId } = await render(
React.cloneElement(element, { slotProps, className: 'custom' }),
);
const slotComponent = queryByTestId('custom');
expect(slotComponent).not.to.equal(null);
});
});
}

function testSlotPropsCallbackWithPropsAsOwnerState(
element: React.ReactElement<any>,
getOptions: () => ConformanceOptions,
) {
const { render, slots } = getOptions();

if (!render) {
throwMissingPropError('render');
}

forEachSlot(slots, (slotName) => {
it(`sets custom properties on the ${slotName} slot's element with the slotProps.${slotName} callback using the ownerState`, async () => {
const slotProps = {
[slotName]: (ownerState: Record<string, any>) => ({
'data-testid': ownerState.className,
Expand Down Expand Up @@ -1068,6 +1095,7 @@ const fullSuite = {
rootClass: testRootClass,
slotPropsProp: testSlotPropsProp,
slotPropsCallback: testSlotPropsCallback,
slotPropsCallbackWithPropsAsOwnerState: testSlotPropsCallbackWithPropsAsOwnerState,
slotsProp: testSlotsProp,
themeDefaultProps: testThemeDefaultProps,
themeStyleOverrides: testThemeStyleOverrides,
Expand Down Expand Up @@ -1120,7 +1148,12 @@ function describeConformance(
(testKey) => only.includes(testKey) && !skip.includes(testKey as keyof typeof fullSuite),
) as (keyof typeof fullSuite)[];

const slotBasedTests = ['slotsProp', 'slotPropsProp', 'slotPropsCallback'];
const slotBasedTests = [
'slotsProp',
'slotPropsProp',
'slotPropsCallback',
'slotPropsCallbackWithPropsAsOwnerState',
];

if (!slots) {
// if `slots` are not defined, do not run tests that depend on them
Expand Down
1 change: 1 addition & 0 deletions packages/mui-material/src/FilledInput/FilledInput.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ describe('<FilledInput />', () => {
'componentProp',
'componentsProp',
'slotPropsCallback', // not supported yet
'slotPropsCallbackWithPropsAsOwnerState', // not supported yet
],
}));

Expand Down
1 change: 1 addition & 0 deletions packages/mui-material/src/Input/Input.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ describe('<Input />', () => {
'componentProp',
'componentsProp',
'slotPropsCallback', // not supported yet
'slotPropsCallbackWithPropsAsOwnerState', // not supported yet
],
}));

Expand Down
1 change: 1 addition & 0 deletions packages/mui-material/src/InputBase/InputBase.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ describe('<InputBase />', () => {
skip: [
'componentProp',
'slotPropsCallback', // not supported yet
'slotPropsCallbackWithPropsAsOwnerState', // not supported yet
],
}));

Expand Down
1 change: 1 addition & 0 deletions packages/mui-material/src/ListItem/ListItem.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ describe('<ListItem />', () => {
skip: [
'componentsProp',
'slotPropsCallback', // not supported yet
'slotPropsCallbackWithPropsAsOwnerState', // not supported yet
],
}));

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ describe('<OutlinedInput />', () => {
'componentProp',
'componentsProp',
'slotPropsCallback', // not supported yet
'slotPropsCallbackWithPropsAsOwnerState', // not supported yet
],
}));

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@ describe('<PaginationItem />', () => {
'slotsProp',
'slotPropsProp',
'slotPropsCallback', // not supported yet
'slotPropsCallbackWithPropsAsOwnerState', // not supported yet
],
}));

Expand Down
1 change: 1 addition & 0 deletions packages/mui-material/src/Popper/Popper.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@ describe('<Popper />', () => {
'themeStyleOverrides',
'themeVariants',
'slotPropsCallback', // not supported yet
'slotPropsCallbackWithPropsAsOwnerState', // not supported yet
],
}));

Expand Down
1 change: 1 addition & 0 deletions packages/mui-material/src/Slider/Slider.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,7 @@ describe('<Slider />', () => {
},
skip: [
'slotPropsCallback', // not supported yet
'slotPropsCallbackWithPropsAsOwnerState', // not supported yet
],
}),
);
Expand Down
7 changes: 6 additions & 1 deletion packages/mui-material/src/TextField/TextField.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,12 @@ describe('<TextField />', () => {
testWithElement: null,
},
},
only: ['slotsProp', 'slotPropsProp', 'slotPropsCallback'],
only: [
'slotsProp',
'slotPropsProp',
'slotPropsCallback', // not supported yet
'slotPropsCallbackWithPropsAsOwnerState', // not supported yet
],
}),
);

Expand Down