@wdio/native-spy
v1.1.0
Published
Minimal mock function implementation for WebdriverIO Native Desktop Services
Downloads
19,415
Keywords
Readme
@wdio/native-spy
Minimal mock function implementation for WebdriverIO Native Desktop Services.
Overview
This package provides a lightweight mock/spy implementation (fn()) for use in Electron and Tauri desktop testing scenarios where @vitest/spy cannot be bundled directly into the application context.
Usage
import { fn } from '@wdio/native-spy';
// Create a mock function
const mock = fn();
// Set return values
mock.mockReturnValue('hello');
console.log(mock()); // 'hello'
// Track calls
mock('world');
console.log(mock.calls.length); // 1
console.log(mock.calls[0].args); // ['world']API
fn<T>(implementation?)
Creates a mock function with the optional implementation.
Mock Methods
mockReturnValue(value)- Set return valuemockReturnValueOnce(value)- Set return value for next callmockResolvedValue(value)- Set resolved value (for async functions)mockResolvedValueOnce(value)- Set resolved value for next callmockRejectedValue(reason)- Set rejection errormockRejectedValueOnce(reason)- Set rejection error for next callmockImplementation(fn)- Set implementation functionmockImplementationOnce(fn)- Set implementation for next callmockClear()- Clear call historymockReset()- Reset to initial statemockRestore()- Restore original implementationmockName(name)- Set mock namegetMockName()- Get mock name
Mock Properties
calls- Array of call informationresults- Array of call resultsinvocationCallOrder- Order of invocationsinstances- Array of instances (for constructor mocks)
License
MIT
