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] Add test validator to improve DX #25854

Merged
merged 6 commits into from
Apr 23, 2021
Merged
Changes from 5 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
46 changes: 40 additions & 6 deletions test/utils/describeConformanceV5.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,13 @@ import {
testRootClass,
} from './describeConformance';

function throwMissingPropError(field) {
throw new Error(`missing "${field}" in options

> describeConformanceV5(element, () => options)
`);
}

/**
* Material-UI components have a `components` prop that allows rendering a different
* Components from @inheritComponent
Expand Down Expand Up @@ -41,6 +48,15 @@ function testThemeDefaultProps(element, getOptions) {
it("respect theme's defaultProps", () => {
const testProp = 'data-id';
const { muiName, render } = getOptions();

if (!muiName) {
throwMissingPropError('muiName')
}

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

const theme = createMuiTheme({
components: {
[muiName]: {
Expand Down Expand Up @@ -76,6 +92,14 @@ function testThemeStyleOverrides(element, getOptions) {
return;
}

if (!muiName) {
throwMissingPropError('muiName')
}

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

const testStyle = {
marginTop: '13px',
};
Expand Down Expand Up @@ -199,6 +223,14 @@ function testThemeVariants(element, getOptions) {
throw new Error('missing testVariantProps');
}

if (!muiName) {
throwMissingPropError('muiName')
}

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

const testStyle = {
marginTop: '13px',
};
Expand Down Expand Up @@ -251,14 +283,16 @@ const fullSuite = {
export default function describeConformanceV5(minimalElement, getOptions) {
const { after: runAfterHook = () => {}, only = Object.keys(fullSuite), skip = [] } = getOptions();

const filteredTests = Object.keys(fullSuite).filter(
(testKey) => only.indexOf(testKey) !== -1 && skip.indexOf(testKey) === -1,
);

describe('Material-UI component API', () => {
after(runAfterHook);

Object.keys(fullSuite)
.filter((testKey) => only.indexOf(testKey) !== -1 && skip.indexOf(testKey) === -1)
.forEach((testKey) => {
const test = fullSuite[testKey];
test(minimalElement, getOptions);
});
filteredTests.forEach((testKey) => {
const test = fullSuite[testKey];
test(minimalElement, getOptions);
});
});
}