Skip to main content
The UI extensions SDK provides comprehensive mocking support for testing extensions without making real API calls or requiring access to actual HubSpot data. You can mock extension context data, React hooks, extension actions, and serverless function calls. The mocking functionality is built on tinyspy, a minimal spy library. Each mock function is created using tinyspy’s spyOn function, which means all mock functions expose the standard tinyspy spy properties and methods for advanced testing scenarios.

Quick reference

Mock Types Available: Spy Methods:
  • nextResult(value): set the return value for the next single call only
  • willCall(fn): provide a custom implementation that persists across all calls
  • reset(): clear call history while keeping the mock implementation
  • restore(): restore to the default mock behavior
Spy Properties:
  • called: boolean indicating if called
  • callCount: number of times called
  • calls: array of argument arrays
  • returns: array of return values

Automatic mocks based on extension point location

When you create a renderer with createRenderer(extensionPointLocation), the testing SDK automatically creates appropriate mocks for the Extension Point API based on the location you specify. This includes:
  • context: Extension point-specific context data (user info, portal info, CRM data, variables, etc.)
  • actions: Extension point-specific actions (addAlert, reloadPage, fetchCrmObjectProperties, etc.)
  • runServerlessFunction(): A mock implementation for calling serverless functions
A renderer created with createRenderer('crm.record.tab') will provide different context and actions than one created with createRenderer('settings'). Always use the extension point location that matches where your component will be used.

Mocking React hooks

Default mock implementations

The testing SDK automatically provides default mock implementations for supported hooks. These defaults allow your components to render without additional configuration:
  • useCrmProperties(): Returns fake property values based on property names (e.g., firstnamefake_firstname)
  • useAssociations(): Returns a single fake association result with fake property values

Mocking the next result

Use the nextResult() method to mock the return value for the next single invocation of a hook. This is useful for testing specific states like loading or error conditions. The mock applies only to the next call and then reverts to the default behavior:

Custom mock functions

Use the willCall() method to provide a custom implementation for a hook that persists across all calls. This gives you full control over the hook’s behavior based on the input arguments. Unlike nextResult(), which applies to only the next call, willCall() replaces the mock implementation for all subsequent calls:

Mocking useAssociations

The useAssociations() hook supports the same mocking methods as useCrmProperties():

Mocking Extension Point API

The testing SDK automatically creates mocks for the Extension Point API based on the extension point location you provide to createRenderer(). These mocks allow you to test components that use context, actions, or runServerlessFunction() from the Extension Point API.

Mocking context

The context object is automatically populated with fake data appropriate for the extension point location. You can access and customize it via mocks.context:
You can customize the context before rendering:
The shape of the context object depends on the extension point location:
  • CRM locations ('crm.record.tab', 'crm.record.sidebar', 'crm.preview', 'helpdesk.sidebar'): Include user, portal, crm (with objectId and objectTypeId), and variables
  • Settings location ('settings'): Include user and portal
  • Home location ('home'): Include user and portal

Mocking actions

The actions object contains extension point-specific functions that are automatically mocked as spies. You can use these spies to verify that your component calls the correct actions:
Available actions vary by extension point location:
  • CRM locations: addAlert(), reloadPage(), fetchCrmObjectProperties(), openIframeModal(), refreshObjectProperties(), onCrmPropertiesUpdate(), copyTextToClipboard(), closeOverlay()
  • Settings location: addAlert(), copyTextToClipboard(), closeOverlay(), reloadPage(), openIframeModal()
  • Home location: addAlert(), copyTextToClipboard(), closeOverlay(), reloadPage(), openIframeModal()

Mocking serverless functions

The runServerlessFunction() mock allows you to test components that call serverless functions:
You can also use willCall() to provide custom logic:

Advanced mock features

Since mocks are built on tinyspy, they expose additional properties and methods for advanced testing scenarios:

Spy properties

All mocks provide the following properties to inspect how the function was called:
  • called: boolean indicating if the function was called
  • callCount: number of times the function was called
  • calls: array of argument arrays for each call
  • results: array of results for each call (in format ['ok', value] or ['error', error])
  • returns: array of return values for each successful call

Resetting mocks

Use the reset() method to clear all call history while keeping the mock implementation. This is useful when you want to reuse a mock across multiple test cases:

Restoring original implementation

Use the restore() method to restore the mock to its default mocked implementation. This is useful when you’ve customized a mock with willCall() and want to return to the default behavior:
For more advanced usage and features, see the tinyspy documentation.
Last modified on March 29, 2026