I have an error when testing with sinon.js (and mocha). The error occurs when I run the all test scripts via npm, but not when I run an individual script through the IDE. Running the test script individually works ok, and the test passes.
I.e. I have a directory with several test scripts in it. When I run one script on its own the tests pass. When I run all scripts in the directory the tess fail with the errors:
Test will fail with
TypeError: Attempted to wrap getVariable which is already wrapped
While the other tests fail with:
TypeError: Cannot read property 'restore' of undefined
Both test scripts start with the same code:
const
assert = require('assert'),
sinon = require('sinon');
global.context = {
getVariable: function(s) {}
};
var contextGetVariableMethod;
beforeEach(function () {
contextGetVariableMethod = sinon.stub(context, 'getVariable');
});
afterEach(function () {
contextGetVariableMethod.restore();
});
I guess that mocha is running both test simultaneously? And the tests are interfering with one another. I'm confused why the scope of the tests is not independent though... perhaps its the use of global
?
thanks