| 200 | } |
| 201 | |
| 202 | export function behavesAsComponent({Component, toRender, options}: BehavesAsComponent) { |
| 203 | options = options || {} |
| 204 | |
| 205 | const getElement = () => (toRender ? toRender() : <Component />) |
| 206 | |
| 207 | if (!options.skipSx) { |
| 208 | it('implements sx prop behavior', () => { |
| 209 | expect(getElement()).toImplementSxBehavior() |
| 210 | }) |
| 211 | } |
| 212 | |
| 213 | if (!options.skipAs) { |
| 214 | it('respects the as prop', () => { |
| 215 | const As = React.forwardRef<HTMLDivElement>((_props, ref) => <div className="as-component" ref={ref} />) |
| 216 | const elem = React.cloneElement(getElement(), {as: As}) |
| 217 | expect(render(elem)).toEqual(render(<As />)) |
| 218 | }) |
| 219 | } |
| 220 | |
| 221 | it('sets a valid displayName', () => { |
| 222 | expect(Component.displayName).toMatch(COMPONENT_DISPLAY_NAME_REGEX) |
| 223 | }) |
| 224 | } |
| 225 | |
| 226 | // eslint-disable-next-line @typescript-eslint/no-explicit-any |
| 227 | export function checkExports(path: string, exports: Record<any, any>): void { |