In get-platform.js
we have the following function:
export default function getPlatform() {
return process.platform;
}
We want mock out the value of process.platform
per test.
You can't directly overwrite the value and restore (e.g. process.platform = 'foo'
)
because if you inspect the object property, 'writeable' is set to false:
$ node -p "Object.getOwnPropertyDescriptor(process, 'platform')"
{
value: 'darwin',
writable: false,
enumerable: true,
configurable: true
}
See: jestjs/jest#2227
A generalized version of this has been suggested here: jestjs/jest#2227 (comment)