request-mocking-protocol
Version:
A protocol for declarative mocking of HTTP requests
24 lines (20 loc) • 520 B
text/typescript
/**
* Mock response utils.
*/
import set from 'lodash/set';
/**
* Patches object by provided set of keyPath and value pairs.
*/
export function patchObject(
obj?: Record<string, unknown> | null,
patchSchema?: Record<string, unknown>,
) {
if (obj && typeof obj === 'object' && patchSchema) {
Object.keys(patchSchema).forEach((keyPath) => {
set(obj, keyPath, patchSchema[keyPath]);
});
}
}
export async function wait(ms: number) {
return new Promise((resolve) => setTimeout(resolve, ms));
}