Open trivikr opened 1 year ago
jest
test("replaceProperty", () => { expect(process.env.TEST_ENV_KEY_1).toBeUndefined(); expect(process.env.TEST_ENV_KEY_2).toBeUndefined(); jest.replaceProperty(process, 'env', { TEST_ENV_KEY_1: "test1", TEST_ENV_KEY_2: "test2" }); expect(process.env.TEST_ENV_KEY_1).toBe("test1"); expect(process.env.TEST_ENV_KEY_2).toBe("test2"); jest.restoreAllMocks(); expect(process.env.TEST_ENV_KEY_1).toBeUndefined(); expect(process.env.TEST_ENV_KEY_2).toBeUndefined(); });
test("replaceProperty", () => { expect(process.env.TEST_ENV_KEY_1).toBeUndefined(); expect(process.env.TEST_ENV_KEY_2).toBeUndefined(); vi.stubEnv("TEST_ENV_KEY_1", "test1"); vi.stubEnv("TEST_ENV_KEY_2", "test2"); expect(process.env.TEST_ENV_KEY_1).toBe("test1"); expect(process.env.TEST_ENV_KEY_2).toBe("test2"); vi.restoreAllMocks(); vi.unstubAllEnvs(); expect(process.env.TEST_ENV_KEY_1).toBeUndefined(); expect(process.env.TEST_ENV_KEY_2).toBeUndefined(); });
Refs: https://github.com/vitest-dev/vitest/issues/2831
Self-service
Template name
jest
Input code
Expected Output
Additional context
Refs: https://github.com/vitest-dev/vitest/issues/2831