-
Notifications
You must be signed in to change notification settings - Fork 1
Open
Description
I did run into a problem yesterday where I found that the state of objects are shared between tests, and this can cause tests to fail. I made a minimal example to illustrate this.
Create the following files:
data.js
var dataObject = {
data: [],
addData: function(d) {
this.data.push(d);
return this.data.length;
}
};
export { dataObject };1.test.js
import { dataObject } from "./data";
export default {
"add one data element": [dataObject.addData(5), 1]
};2.test.js
import { dataObject } from "./data";
export default {
"add one data element": [dataObject.addData(5), 1]
};Note that the two tests are exactly the same test
When I run the tests, test 1 will pass and test 2 will fail, because it turns out that the dataObject is shared between them and the environment is not reset between tests.
PASS 1.test.js
✓ add one data element
FAIL 2.test.js
✕ add one data element
FAIL 2.test.js
● add one data element
encountered 2 but expected 1
Expected result
Tests are run independent of each other and changes you do in one test should not effect the result in another test.
Please let me know if there is anything I can do in my tests, or anything I can help out with in tead to solve this.