Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
Prev Previous commit
Next Next commit
Remove enzyme from describeRef test
  • Loading branch information
DiegoAndai authored and aarongarciah committed Jun 18, 2024
commit c9842727d04d26c20ab0ba68d34477dde219dd1a
45 changes: 9 additions & 36 deletions packages-internal/test-utils/src/describeConformance.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -65,34 +65,6 @@ export interface ConformanceOptions {
createTheme?: (arg: any) => any;
}

/**
* @param {object} node
* @returns
*/
function assertDOMNode(node: unknown) {
// duck typing a DOM node
expect(typeof (node as HTMLElement).nodeName).to.equal('string');
}

/**
* Utility method to make assertions about the ref on an element
* The element should have a component wrapped in withStyles as the root
*/
function testRef(
element: React.ReactElement<any>,
mount: ConformanceOptions['mount'],
onRef: (instance: unknown, wrapper: import('enzyme').ReactWrapper) => void = assertDOMNode,
) {
if (!mount) {
throwMissingPropError('mount');
}

const ref = React.createRef();

const wrapper = mount(<React.Fragment>{React.cloneElement(element, { ref })}</React.Fragment>);
onRef(ref.current, wrapper);
}

/**
* Glossary
* - root component:
Expand Down Expand Up @@ -209,16 +181,17 @@ export function describeRef(
describe('ref', () => {
it(`attaches the ref`, () => {
// type def in ConformanceOptions
const { inheritComponent, mount, refInstanceof } = getOptions();
const { render, refInstanceof } = getOptions();

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

testRef(element, mount, (instance, wrapper) => {
expect(instance).to.be.instanceof(refInstanceof);
const ref = React.createRef();

if (inheritComponent !== undefined && (instance as HTMLElement).nodeType === 1) {
const rootHost = findOutermostIntrinsic(wrapper);
expect(instance).to.equal(rootHost.instance());
}
});
render(React.cloneElement(element, { ref }));

expect(ref.current).to.be.instanceof(refInstanceof);
});
});
}
Expand Down
2 changes: 1 addition & 1 deletion packages/mui-material/src/Grow/Grow.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ describe('<Grow />', () => {
};

describeConformance(
<Grow in>
<Grow in appear={false}>
<div />
</Grow>,
() => ({
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ describe('<NativeSelectInput />', () => {
const { render } = createRenderer();

describeConformance(<NativeSelectInput IconComponent="div" />, () => ({
render,
only: ['refForwarding'],
refInstanceof: window.HTMLSelectElement,
muiName: 'MuiNativeSelectInput',
Expand Down