A set of useful utility functions.
Alias: rs.stubEnv
Type: (name: string, value: string | undefined) => Rstest
Temporarily sets an environment variable in process.env and import.meta.env to the specified value. Useful for testing code that depends on environment variables.
value is undefined, the variable will be removed from process.env and import.meta.env.rstest.unstubAllEnvs() to restore all environment variables changed by this method.Example:
Alias: rs.unstubAllEnvs
Type: () => Rstest
Restores all environment variables that were changed using rstest.stubEnv to their original values.
unstubEnvs config is enabled.Example:
Alias: rs.stubGlobal
Type: (name: string | number | symbol, value: unknown) => Rstest
Temporarily sets a global variable to the specified value. Useful for mocking global objects or functions.
rstest.unstubAllGlobals() to restore all globals changed by this method.Example:
Alias: rs.unstubAllGlobals
Type: () => Rstest
Restores all global variables that were changed using rstest.stubGlobal to their original values.
unstubGlobals config is enabled.Example:
Alias: rs.setConfig
Type:
Dynamically updates the runtime configuration for the current test file. Useful for temporarily overriding test settings such as timeouts, concurrency, or mock behavior.
Example:
Alias: rs.resetConfig
Type: () => void
Resets the runtime configuration that was changed using rstest.setConfig back to the default values.