To stub process.env in Node.js, we set the values in our test.
For instance, we write
it("does something interesting", () => {
process.env.NODE_ENV = "test";
// ...
});
afterEach(() => {
delete process.env.NODE_ENV;
});
to set the process.env.NODE_ENV to 'test' in our test.
And we delete the property in the afterEach callback so it’s removed after each test.