New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
sinon@next: sinon.replace only works on own property #1695
Comments
I tried adding a test to reproduce your scenario it("should replace property on prototype", function () {
var Person = function (name) {
this.name = name;
};
var Customer = function (name) {
Person.call(this, name);
};
Customer.prototype = Object.create(Person.prototype);
Customer.prototype.constructor = Customer;
var customer = new Customer("Some Name");
var replacement = "Some Other Name";
this.sandbox.replace(customer, "name", replacement);
assert.equals(customer.name, replacement);
}); However, this passes with no changes to I don't think I understood your description correctly. Can you suggest an improvement to the test, that would make it clear what |
@mroderick The reason your example doesn't fail is because Anyway, I've created #1704 to illustrate the issue with a failing test. |
Fixed with #1705 |
While playing with #1586, I noticed that
sinon.replace(obj, 'prop', fake)
only works if 'prop' is an own property ofobj
. I can only make this work withsinon.replace(Object.getPrototypeOf(obj), 'prop', fake)
.sinon.replace
should allow to replace properties up the prototype chain, likesandbox.stub
does.The text was updated successfully, but these errors were encountered: