MCPcopy Index your code
hub / github.com/primer/react / behavesAsComponent

Function behavesAsComponent

packages/react/src/utils/testing.tsx:202–224  ·  view source on GitHub ↗
({Component, toRender, options}: BehavesAsComponent)

Source from the content-addressed store, hash-verified

200}
201
202export 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
227export function checkExports(path: string, exports: Record<any, any>): void {

Callers 15

Truncate.test.tsxFile · 0.90
Tooltip.test.tsxFile · 0.90
Heading.test.tsxFile · 0.90
Flash.test.tsxFile · 0.90
Text.test.tsxFile · 0.90
ActionBar.test.tsxFile · 0.90
testTokenComponentFunction · 0.90
Hidden.test.tsxFile · 0.90

Calls 2

renderFunction · 0.90
getElementFunction · 0.85

Tested by 1

testTokenComponentFunction · 0.72