vegan-ipsum
Version:
Generates passages of vegan-themed placeholder text suitable for use in web pages, graphics, and more. Works in the browser, NodeJS, and React Native.
53 lines (52 loc) • 1.73 kB
TypeScript
/**
* Helper to mock and restore Node `process.platform` during tests.
*
* Provides simple methods to set and reset the platform value for unit tests.
*/
declare class ProcessHelper {
/** Cache of the original `process.platform` value. */
cachedPlatform: string;
/** Cache of the original `global.navigator` value. */
cachedNavigator: any;
/**
* Create a new ProcessHelper and capture the current platform.
*
* @example
* const p = new ProcessHelper();
*/
constructor();
/**
* Reset `process.platform` to the originally cached value.
*
* @example
* const p = new ProcessHelper();
* p.setPlatform('win32');
* p.resetPlatform(); // restores original platform
*/
resetPlatform(): void;
/**
* Set `process.platform` to a provided value for the duration of a test.
* Passing no argument will set the platform to `undefined`, allowing
* tests to simulate a missing/unknown platform.
*
* @param {string | undefined} [platform] - The platform string to apply (e.g. 'win32') or `undefined`.
*
* @example
* const p = new ProcessHelper();
* p.setPlatform('darwin');
* p.setPlatform(); // sets platform to undefined
*/
setPlatform(platform?: string): void;
/**
* Set the global `navigator` object for the duration of a test.
* Passing no argument sets `navigator` to `undefined`.
*
* @param {unknown} [obj] - The object to set as `global.navigator` or `undefined`.
*/
setNavigator(obj?: unknown): void;
/**
* Restore the original `navigator` value cached at construction.
*/
resetNavigator(): void;
}
export default ProcessHelper;