I have been facing this issue with jest, where the data i set in one test is creeping into another test and causing it to fail.
Let me try to show some code
spec.ts
const MOCK_PRODUCT = require('../dummydata/dummydata.json');
describe('function 1', () => {
test('something', () => {
const productData = MOCK_PRODUCT;
expect(...) // works fine
});
test('something else', () => {
const productData = MOCK_PRODUCT;
productData.someField.push({...})
expect(...) // works fine
});
});
describe('function 2', () => {
test('something more', () => {
const productData = MOCK_PRODUCT;
expect(...) // fails
});
});
My test file goes like this. There is a describe block for each function and multiple tests inside the describe block.
What i observe is that, when i changed the productData in second test as you see above, the changed data is available in all the tests in the next describe block, causing them to fail.
Am i doing something wrong? is something missing?