createRenderer
createRenderer()
Creates a Renderer object with methods for rendering UI extension components and querying the rendered output.
Parameters:
extensionPointLocation:ExtensionPointLocation: the extension point location (e.g.,'crm.record.tab','settings','home'). This determines which extension point-specific APIs are available in the automatically created mocks forcontext,actions, andrunServerlessFunction.
Renderer
Import:
Common query methods
The following query methods are available onRenderer and select node types (RenderedRootNode, RenderedElementNode, RenderedFragmentNode):
Common parameters:
component:HubSpotReactComponent: the component type to find.matcher?:ElementMatcher: an optional matcher to filter the elements.
find
find()
Find a single element matching the component type. Throws an error if not found or multiple matches exist.
Parameters:
component:HubSpotReactComponentmatcher?:ElementMatcher
RenderedElementNode
findAll
findAll()
Find all elements matching the component type. Returns an array.
Parameters:
component:HubSpotReactComponentmatcher?:ElementMatcher
RenderedElementNode[]
findChild
findChild()
Find a direct child element matching the component type. Throws an error if not found or multiple matches exist.
Parameters:
component:HubSpotReactComponentmatcher?:ElementMatcher
RenderedElementNode
findAllChildren
findAllChildren()
Find all direct child elements matching the component type. Returns an array.
Parameters:
component:HubSpotReactComponentmatcher?:ElementMatcher
RenderedElementNode[]
maybeFind
maybeFind()
Find a single element matching the component type. Returns null if not found or multiple matches exist.
Parameters:
component:HubSpotReactComponentmatcher?:ElementMatcher
RenderedElementNode | null
maybeFindChild
maybeFindChild()
Find a direct child element matching the component type. Returns null if not found or multiple matches exist.
Parameters:
component:HubSpotReactComponentmatcher?:ElementMatcher
RenderedElementNode | null
Renderer
Renderer
The object returned by createRenderer() with the following methods and properties:
render
render()
Renders a UI extension component and returns the root node.
Parameters:
node: ReactNode: the React component to render
RenderedRootNode
Query methods
All common query methods are available:find(), findAll(), findChild(), findAllChildren(), maybeFind(), maybeFindChild()
findByTestId
findByTestId()
Find a component by its testId prop. This is the recommended way to find components when you have control over the component’s props.
Parameters:
component:HubSpotReactComponent: the component type to find.testId: string: the test ID to search for.
RenderedElementNode
Throws:
ComponentNotFoundByTestIdErrorif no component with the specifiedtestIdis found.ComponentMismatchedByTestIdErrorif a component with thetestIdexists but the component type doesn’t match.FindInvalidComponentErrorif the target component is invalid.
maybeFindByTestId
maybeFindByTestId()
Find a component by its testId prop. Returns null if no match is found. Still throws an error if the test ID exists but the component type doesn’t match.
Parameters:
component:HubSpotReactComponent: the component type to find.testId: string: the test ID to search for.
RenderedElementNode | null
Throws:
ComponentMismatchedByTestIdErrorif a component with thetestIdexists but the component type doesn’t match.FindInvalidComponentErrorif the target component is invalid.
waitFor
waitFor()
Wait for an async condition to be met (useful for testing async updates).
Parameters:
check: () => void: a function that throws an error if the condition is not met.options?:WaitForOptions: optional configuration options.
Promise<void>
debugLog
debugLog()
Log the rendered tree to the console for debugging.
Parameters:
label?: string: an optional label for the log output.
void
getRootNode
getRootNode()
Get the root node of the rendered tree.
Return: RenderedRootNode
mocks
Object containing mock implementations and spies (see Mocking for detailed usage). Properties:mocks.useCrmProperties():FunctionSpyfor theuseCrmProperties()hook.mocks.useAssociations():FunctionSpyfor theuseAssociations()hook.mocks.context: mockcontextobject for the Extension Point APImocks.actions: object containingFunctionSpyinstances for Extension Point API actions.mocks.runServerlessFunction():FunctionSpyfor therunServerlessFunction()function.
FunctionSpy
FunctionSpy
Each mocked function (hooks, actions, runServerlessFunction()) is a tinyspy spy that provides inspection and control over function calls.
called
called
Boolean indicating if the function was called at least once.
Type: boolean
callCount
callCount
Number of times the function was called.
Type: number
calls
calls
Array of argument arrays for each call. Access arguments via spy.calls[0][0], spy.calls[0][1], etc.
Type: any[][]
results
results
Array of tuples representing each call’s result:
- Success:
['ok', returnValue] - Error:
['error', errorValue]
(['ok', any] | ['error', any])[]
returns
returns
Array of return values for each successful call (shorthand for filtering results by 'ok').
Type: any[]
nextResult
nextResult()
Set the return value for the next invocation only.
Parameters:
value: any: the value to return on the next call.
FunctionSpy
willCall
willCall()
Replace the mock implementation with a custom function.
Parameters:
fn: Function: the custom implementation function
FunctionSpy
reset
reset()
Clear all call history while preserving the mock implementation.
Return: FunctionSpy
restore
restore()
Restore the spy to its original default implementation and clear call history.
Return: FunctionSpy
Example:
HubSpotReactComponent
HubSpotReactComponent
Any of the HubSpot UI component types exported by the UI Extensions SDK. These are used with query methods to find rendered components.
Import:
RenderedElementNode
RenderedElementNode
Represents a rendered HubSpot UI component element in the tree.
nodeType
nodeType
Always RenderedNodeType.Element
Type: RenderedNodeType.Element
name
name
Component name (e.g., 'Button', 'Text').
Type: string
props
props
Component props object (fragments in props are converted to RenderedFragmentNode).
Type: Record<string, any>
text
text
Concatenated text content of all descendant text nodes, or null if none.
Type: string | null
childNodes
childNodes
Array of child nodes.
Type: RenderedNode[]
Query methods
All common query methods are available:find(), findAll(), findChild(), findAllChildren(), maybeFind(), maybeFindChild()
isMatch
isMatch()
Check if this node matches a component type and optional matcher.
Parameters:
component:HubSpotReactComponentmatcher?:ElementMatcher
boolean
trigger
trigger()
Trigger an event handler prop (e.g., node.trigger('onClick')).
Parameters:
eventPropName: string: the name of the event handler prop.eventArg?: any: an optional argument to pass to the event handler.
void
debugLog
debugLog()
Log the element tree to the console for debugging.
Parameters:
label?: string: an optional label for the log output
void
toString
toString()
Get string representation of the node.
Return: string
RenderedFragmentNode
RenderedFragmentNode
Represents the root of the rendered fragment.
nodeType
nodeType
Always RenderedNodeType.Fragment
Type: RenderedNodeType.Fragment
childNodes
childNodes
Array of child nodes.
Type: RenderedNode[]
Query methods
All common query methods are available:find(), findAll(), findChild(), findAllChildren(), maybeFind(), maybeFindChild()
isMatch
isMatch()
Check if this node matches a component type and optional matcher (will always return false).
Parameters:
component:HubSpotReactComponentmatcher?:ElementMatcher
boolean
debugLog
debugLog()
Log the element tree to the console for debugging.
Parameters:
label?: string: an optional label for the log output.
void
toString
toString()
Get string representation of the node.
Return: string
RenderedRootNode
RenderedRootNode
Represents the root of the entire rendered tree. This is the node returned by renderer.render().
nodeType
nodeType
Always RenderedNodeType.Root
Type: RenderedNodeType.Root
childNodes
childNodes
Array of child nodes.
Type: RenderedNode[]
Query methods
All common query methods are available:find(), findAll(), findChild(), findAllChildren(), maybeFind(), maybeFindChild()
isMatch
isMatch()
Check if this node matches a component type and optional matcher (will always return false).
Parameters:
component:HubSpotReactComponentmatcher?:ElementMatcher
boolean
debugLog
debugLog()
Log the element tree to the console for debugging.
Parameters:
label?: string: an optional label for the log output.
void
toString
toString()
Get string representation of the node.
Return: string
RenderedTextNode
RenderedTextNode
Represents a text node in the rendered tree. Text nodes are leaf nodes automatically created when rendering string content in your components.
Note: Text nodes do not have childNodes or query methods since they are leaf nodes.
nodeType
nodeType
Always RenderedNodeType.Text
Type: RenderedNodeType.Text
text
text
The text content as a string.
Type: string
isMatch
isMatch()
Check if this node matches a component type and optional matcher (will always return false).
Parameters:
component:HubSpotReactComponentmatcher?:ElementMatcher
boolean
toString
toString()
Get string representation of the node.
Return: string
RenderedNode
RenderedNode
Union type representing any node in the rendered tree:
RenderedElementNode, RenderedRootNode, RenderedFragmentNode, RenderedTextNode)
RenderedNodeType
RenderedNodeType
Enum of all possible node types in the rendered tree:
ElementMatcher
ElementMatcher
Optional parameter for query methods to filter elements beyond just component type.
A matcher can be:
- Partial props object: matches if the element has all specified prop values
- Predicate function: matches if the function returns
truefor the element node
ExtensionPointLocation
ExtensionPointLocation
A string literal union type representing valid extension point locations where UI extensions can be rendered.
Type definition:
context, actions, and runServerlessFunction.
Example:
WaitForOptions
WaitForOptions
Options for the waitFor() function.
timeoutInMs
timeoutInMs
Maximum time to wait in milliseconds (default: 1000).
Type: number | undefined
Default: 1000
Utility Functions
Type guard functions for narrowing TypeScript types of rendered nodes and checking component matches. Import:isRenderedElementNode
isRenderedElementNode()
Check if a node is a RenderedElementNode and narrow its type.
Parameters:
node:RenderedNode| null | undefined
node is RenderedElementNode
isRenderedTextNode
isRenderedTextNode()
Check if a node is a RenderedTextNode and narrow its type.
Parameters:
node:RenderedNode| null | undefined
node is RenderedTextNode
isRenderedRootNode
isRenderedRootNode()
Check if a node is a RenderedRootNode and narrow its type.
Parameters:
node:RenderedNode| null | undefined
node is RenderedRootNode
isRenderedFragmentNode
isRenderedFragmentNode()
Check if a node is a RenderedFragmentNode and narrow its type.
Parameters:
node:RenderedNode| null | undefined
node is RenderedFragmentNode
isMatch
isMatch()
Check if a node matches a specific component type and optional matcher criteria, narrowing to RenderedElementNode<TProps>. Also available as a method on all rendered nodes.
Type Parameters:
TProps: the props type of the component.
node:RenderedNode| null | undefinedcomponent:HubSpotReactComponentmatcher?:ElementMatcher
node is RenderedElementNode<TProps>
Example: