-
-
Notifications
You must be signed in to change notification settings - Fork 32.5k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[test] Add conformance test suite for v5 (#23798)
- Loading branch information
Showing
7 changed files
with
80 additions
and
12 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,58 @@ | ||
/* eslint-env mocha */ | ||
import { expect } from 'chai'; | ||
import * as React from 'react'; | ||
import { | ||
testClassName, | ||
testPropsSpread, | ||
describeRef, | ||
testRootClass, | ||
findRootComponent, | ||
testReactTestRenderer, | ||
} from './describeConformance'; | ||
|
||
/** | ||
* Material-UI components have a `components` prop that allows rendering a different | ||
* Components from @inheritComponent | ||
* @param {React.ReactElement} element | ||
* @param {() => ConformanceOptions} getOptions | ||
*/ | ||
function testComponentsProp(element, getOptions) { | ||
describe('prop: components', () => { | ||
it('can render another root component with the `components` prop', () => { | ||
const { classes, mount, testComponentsRootPropWith: component = 'em' } = getOptions(); | ||
|
||
const wrapper = mount(React.cloneElement(element, { components: { Root: component } })); | ||
|
||
expect(findRootComponent(wrapper, { classes, component }).exists()).to.equal(true); | ||
}); | ||
}); | ||
} | ||
|
||
const fullSuite = { | ||
componentsProp: testComponentsProp, | ||
mergeClassName: testClassName, | ||
propsSpread: testPropsSpread, | ||
refForwarding: describeRef, | ||
rootClass: testRootClass, | ||
reactTestRenderer: testReactTestRenderer, | ||
}; | ||
|
||
/** | ||
* Tests various aspects of a component that should be equal across Material-UI | ||
* components. | ||
* @param {React.ReactElement} minimalElement - the component with it's minimal required props | ||
* @param {() => ConformanceOptions} getOptions | ||
*/ | ||
export default function describeConformanceV5(minimalElement, getOptions) { | ||
const { after: runAfterHook = () => {}, only = Object.keys(fullSuite), skip = [] } = getOptions(); | ||
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); | ||
}); | ||
}); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters