Function to execute safely
Error object if function throws/rejects, null if successful
// Synchronous error capture
const error = TestValidator.proceed(() => {
throw new Error("Something went wrong");
});
console.log(error?.message); // "Something went wrong"
// Asynchronous error capture
const asyncError = await TestValidator.proceed(async () => {
await failingAsyncOperation();
});
// Success case
const noError = TestValidator.proceed(() => {
return "success";
});
console.log(noError); // null
Safely executes a function and captures any errors without throwing.
Utility function for error handling in tests. Executes the provided function and returns any error that occurs, or null if successful. Supports both synchronous and asynchronous functions. Useful for testing error conditions without stopping test execution.
Function to execute safely
Error object if function throws/rejects, null if successful
// Synchronous error capture
const error = TestValidator.proceed(() => {
throw new Error("Something went wrong");
});
console.log(error?.message); // "Something went wrong"
// Asynchronous error capture
const asyncError = await TestValidator.proceed(async () => {
await failingAsyncOperation();
});
// Success case
const noError = TestValidator.proceed(() => {
return "success";
});
console.log(noError); // null
Safely executes a function and captures any errors without throwing.
Utility function for error handling in tests. Executes the provided function and returns any error that occurs, or null if successful. Supports both synchronous and asynchronous functions. Useful for testing error conditions without stopping test execution.