mocks
Functions
clearMocks()
Clears mocked functions/data injected by the other functions in this module. When using a test runner that doesn’t provide a fresh window object for each test, calling this function will reset tauri specific properties.
Example
Returns
void
Since
1.0.0
Source: https://github.com/tauri-apps/tauri/blob/dev/packages/api/src/mocks.ts#L210
mockConvertFileSrc()
Mock convertFileSrc
function
Parameters
Parameter | Type | Description |
---|---|---|
osName | string | The operating system to mock, can be one of linux, macos, or windows |
Returns
void
Example
Since
1.6.0
Source: https://github.com/tauri-apps/tauri/blob/dev/packages/api/src/mocks.ts#L171
mockIPC()
Intercepts all IPC requests with the given mock handler.
This function can be used when testing tauri frontend applications or when running the frontend in a Node.js context during static site generation.
Examples
Testing setup using vitest:
The callback function can also return a Promise:
Parameters
Parameter | Type |
---|---|
cb | <T >(cmd , payload ?) => Promise <T > |
Returns
void
Since
1.0.0
Source: https://github.com/tauri-apps/tauri/blob/dev/packages/api/src/mocks.ts#L64
mockWindows()
Mocks one or many window labels.
In non-tauri context it is required to call this function before using the @tauri-apps/api/window
module.
This function only mocks the presence of windows,
window properties (e.g. width and height) can be mocked like regular IPC calls using the mockIPC
function.
Examples
Parameters
Parameter | Type | Description |
---|---|---|
current | string | Label of window this JavaScript context is running in. |
…_additionalWindows | string [] | - |
Returns
void
Since
1.0.0
Source: https://github.com/tauri-apps/tauri/blob/dev/packages/api/src/mocks.ts#L142
© 2024 Tauri Contributors. CC-BY / MIT