According to Jest docs:
"Sandboxed test files and automatic global state resets for every test so no two tests conflict with each other."
However my tests conflict.
Code:
// Note: op is from object-path module for deep access by dot path
let config = { name: 'Bob' }
const getConfig = path => {
return op.get(config, path)
}
const setConfig = (path, value) => {
return op.set(config, path, value)
}
Tests:
test('setConfig() updates a deep config value', () => {
const { setConfig, getConfig } = require('services/config')
setConfig('name', 'Woot')
const res = getConfig('name')
expect(res).toBe('Woot')
})
test('getConfig() updates a deep config value', () => {
const { getConfig } = require('services/config')
const res = getConfig('name')
expect(res).toBe('Bob') // Actually Woot
})
The first test modifies the config file causing second test to fail.
From my experience things like process.env do not get sandboxed but this? What am I not understanding about "sandboxing"?