Skip to content

Commit

Permalink
Add verification tests for sinonjs#2226
Browse files Browse the repository at this point in the history
  • Loading branch information
fatso83 committed Mar 9, 2020
1 parent 5436466 commit aac0bc3
Showing 1 changed file with 46 additions and 0 deletions.
46 changes: 46 additions & 0 deletions test/issues/issues-test.js
Expand Up @@ -580,9 +580,11 @@ describe("issues", function() {
function ClassWithoutProps() {
return;
}

function AnotherClassWithoutProps() {
return;
}

ClassWithoutProps.prototype.constructor = ClassWithoutProps;
AnotherClassWithoutProps.prototype.constructor = AnotherClassWithoutProps;
var arg1 = new ClassWithoutProps(); //arg1.constructor.name === ClassWithoutProps
Expand Down Expand Up @@ -640,6 +642,7 @@ describe("issues", function() {
function Foo() {
return;
}

// eslint-disable-next-line mocha/no-setup-in-describe
Foo.prototype.testMethod = function() {
return;
Expand Down Expand Up @@ -679,6 +682,7 @@ describe("issues", function() {
function Foo() {
return;
}

// eslint-disable-next-line mocha/no-setup-in-describe
Foo.prototype.testMethod = function() {
return 1;
Expand Down Expand Up @@ -709,4 +713,46 @@ describe("issues", function() {
refute.equals(fake.lastArg, 3);
});
});

describe("#2226 - props on prototype are not restored correctly", function() {
function createObjectWithPropFromPrototype() {
var proto = {};
var obj = {};

Object.setPrototypeOf(obj, proto);
Object.defineProperty(proto, "test", { writable: true, value: 1 });
return obj;
}

it("should restore fakes shadowing prototype props correctly", function() {
var obj = createObjectWithPropFromPrototype();

var originalPropertyDescriptor = Object.getOwnPropertyDescriptor(obj, "test");

sinon.replace(obj, "test", 2);
var replacedPropertyDescriptor = Object.getOwnPropertyDescriptor(obj, "test");

sinon.restore();
var restoredPropertyDescriptor = Object.getOwnPropertyDescriptor(obj, "test");

assert.isUndefined(originalPropertyDescriptor);
refute.isUndefined(replacedPropertyDescriptor);
assert.isUndefined(restoredPropertyDescriptor);
});

it("should restore stubs shadowing prototype props correctly", function() {
var obj = createObjectWithPropFromPrototype();
var originalPropertyDescriptor = Object.getOwnPropertyDescriptor(obj, "test");

sinon.stub(obj, "test").value(2);
var replacedPropertyDescriptor = Object.getOwnPropertyDescriptor(obj, "test");

sinon.restore();
var restoredPropertyDescriptor = Object.getOwnPropertyDescriptor(obj, "test");

assert.isUndefined(originalPropertyDescriptor);
refute.isUndefined(replacedPropertyDescriptor);
assert.isUndefined(restoredPropertyDescriptor);
});
});
});

0 comments on commit aac0bc3

Please sign in to comment.