-
-
Notifications
You must be signed in to change notification settings - Fork 1.4k
Open
Labels
p2-nice-to-haveNot breaking anything but nice to have (priority)Not breaking anything but nice to have (priority)pr welcome
Description
Clear and concise description of the problem
As a developer using Vitest, I want to be able to use the environment variable stubbing feature to make a given variable be "unset", so that I can easily test my code's behavior when environment variables are not present.
Suggested solution
Expand the functionality of vi.stubEnv(name: string, value: string)
, changing the second argument to value: string | undefined
. If undefined
is given as the value, remove the named variable from process.env
.
Alternative
Alternatively, a new function like vi.stubEnvUnset(name: string)
that does the same thing.
Additional context
My current workaround is to use beforeAll
to store the process.env
entries in question and then delete them, and use afterAll
to restore them.
Validations
- Follow our Code of Conduct
- Read the Contributing Guidelines.
- Read the docs.
- Check that there isn't already an issue that request the same feature to avoid creating a duplicate.
Metadata
Metadata
Assignees
Labels
p2-nice-to-haveNot breaking anything but nice to have (priority)Not breaking anything but nice to have (priority)pr welcome