Skip to main content

with_mock

Function with_mock 

Source
pub fn with_mock<F, R, T>(function_name: &str, mock_fn: F, test_fn: T) -> R
where F: 'static + Send, T: FnOnce() -> R,
Expand description

Run a function with a temporary mock

Automatically restores the original function after execution.

ยงExample

use windjammer_runtime::mock_function::with_mock;

fn get_time() -> i64 { 0 } // Simplified

with_mock("get_time", || 12345i64, || {
    // Mock is active here
    // let time = get_time();
    // assert_eq!(time, 12345);
});
// Mock is automatically cleared