I have multiple files that use sinon to stub the same method Utils.getTimestamp
.
When running the tests files, one at a time all tests pass. When running the tests files at once, the tests fail with: TypeError: "Attempted to wrap getTimestamp which is already wrapped"
In both files, I have the describe blocks with a before and after blocks
In the Before block, I stub the method like: getTimestampStub= sinon.stub(Utils, 'getTimestamp') .returns(myTimestamp);
In the After block I restore the method like: getTimestampStub.restore();
I tried this according to this answer: https://stackoverflow.com/a/36075457/6584537
Sample files:
FILE 1
describe("First Stub", () => {
let getTimestampStub;
before(() => {
getTimestampStub= sinon.stub(Utils, 'getTimestamp') .returns("SOME_TIMESTAMP");
});
it("Should run some code that uses getTimestamp", () => {
// Some code that in the process uses `Utils.getTimestamp`
});
after(() => {
getTimestampStub.restore();
});
});
FILE 2
describe("Second Stub", () => {
let getTimestampStub;
before(() => {
getTimestampStub= sinon.stub(Utils, 'getTimestamp') .returns("SOME_TIMESTAMP");
});
it("Should run some OTHER code that uses getTimestamp", () => {
// Some code that in the process uses `Utils.getTimestamp`
});
after(() => {
getTimestampStub.restore();
});
});