From 3275d18afc1662efedd93010b356e5d9d555ca6b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?M=C3=A1rton=20Salomv=C3=A1ry?= Date: Mon, 4 Mar 2019 10:24:41 +0100 Subject: [PATCH] Document spying on accessors (#1976) --- docs/_releases/latest/spies.md | 36 +++++++++++++++++++++++++++++++++ docs/_releases/v1.17.6/spies.md | 36 +++++++++++++++++++++++++++++++++ docs/_releases/v1.17.7/spies.md | 36 +++++++++++++++++++++++++++++++++ docs/_releases/v2.0.0/spies.md | 36 +++++++++++++++++++++++++++++++++ docs/_releases/v2.1.0/spies.md | 36 +++++++++++++++++++++++++++++++++ docs/_releases/v2.2.0/spies.md | 36 +++++++++++++++++++++++++++++++++ docs/_releases/v2.3.0/spies.md | 36 +++++++++++++++++++++++++++++++++ docs/_releases/v2.3.1/spies.md | 36 +++++++++++++++++++++++++++++++++ docs/_releases/v2.3.2/spies.md | 36 +++++++++++++++++++++++++++++++++ docs/_releases/v2.3.3/spies.md | 36 +++++++++++++++++++++++++++++++++ docs/_releases/v2.3.4/spies.md | 36 +++++++++++++++++++++++++++++++++ docs/_releases/v2.3.5/spies.md | 36 +++++++++++++++++++++++++++++++++ docs/_releases/v2.3.6/spies.md | 36 +++++++++++++++++++++++++++++++++ docs/_releases/v2.3.7/spies.md | 36 +++++++++++++++++++++++++++++++++ docs/_releases/v2.3.8/spies.md | 36 +++++++++++++++++++++++++++++++++ docs/_releases/v2.4.0/spies.md | 36 +++++++++++++++++++++++++++++++++ docs/_releases/v2.4.1/spies.md | 36 +++++++++++++++++++++++++++++++++ docs/_releases/v3.0.0/spies.md | 36 +++++++++++++++++++++++++++++++++ docs/_releases/v3.1.0/spies.md | 36 +++++++++++++++++++++++++++++++++ docs/_releases/v3.2.0/spies.md | 36 +++++++++++++++++++++++++++++++++ docs/_releases/v3.2.1/spies.md | 36 +++++++++++++++++++++++++++++++++ docs/_releases/v3.3.0/spies.md | 36 +++++++++++++++++++++++++++++++++ docs/_releases/v4.0.0/spies.md | 36 +++++++++++++++++++++++++++++++++ docs/_releases/v4.0.1/spies.md | 36 +++++++++++++++++++++++++++++++++ docs/_releases/v4.0.2/spies.md | 36 +++++++++++++++++++++++++++++++++ docs/_releases/v4.1.0/spies.md | 36 +++++++++++++++++++++++++++++++++ docs/_releases/v4.1.1/spies.md | 36 +++++++++++++++++++++++++++++++++ docs/_releases/v4.1.2/spies.md | 36 +++++++++++++++++++++++++++++++++ docs/_releases/v4.1.3/spies.md | 36 +++++++++++++++++++++++++++++++++ docs/_releases/v4.1.4/spies.md | 36 +++++++++++++++++++++++++++++++++ docs/_releases/v4.1.5/spies.md | 36 +++++++++++++++++++++++++++++++++ docs/_releases/v4.1.6/spies.md | 36 +++++++++++++++++++++++++++++++++ docs/_releases/v4.2.0/spies.md | 36 +++++++++++++++++++++++++++++++++ docs/_releases/v4.2.1/spies.md | 36 +++++++++++++++++++++++++++++++++ docs/_releases/v4.2.2/spies.md | 36 +++++++++++++++++++++++++++++++++ docs/_releases/v4.2.3/spies.md | 36 +++++++++++++++++++++++++++++++++ docs/_releases/v4.3.0/spies.md | 36 +++++++++++++++++++++++++++++++++ docs/_releases/v4.4.0/spies.md | 36 +++++++++++++++++++++++++++++++++ docs/_releases/v4.4.1/spies.md | 36 +++++++++++++++++++++++++++++++++ docs/_releases/v4.4.10/spies.md | 36 +++++++++++++++++++++++++++++++++ docs/_releases/v4.4.2/spies.md | 36 +++++++++++++++++++++++++++++++++ docs/_releases/v4.4.3/spies.md | 36 +++++++++++++++++++++++++++++++++ docs/_releases/v4.4.4/spies.md | 36 +++++++++++++++++++++++++++++++++ docs/_releases/v4.4.5/spies.md | 36 +++++++++++++++++++++++++++++++++ docs/_releases/v4.4.6/spies.md | 36 +++++++++++++++++++++++++++++++++ docs/_releases/v4.4.7/spies.md | 36 +++++++++++++++++++++++++++++++++ docs/_releases/v4.4.8/spies.md | 36 +++++++++++++++++++++++++++++++++ docs/_releases/v4.4.9/spies.md | 36 +++++++++++++++++++++++++++++++++ docs/_releases/v4.5.0/spies.md | 36 +++++++++++++++++++++++++++++++++ docs/_releases/v5.0.1/spies.md | 36 +++++++++++++++++++++++++++++++++ docs/_releases/v5.0.10/spies.md | 36 +++++++++++++++++++++++++++++++++ docs/_releases/v5.0.2/spies.md | 36 +++++++++++++++++++++++++++++++++ docs/_releases/v5.0.3/spies.md | 36 +++++++++++++++++++++++++++++++++ docs/_releases/v5.0.4/spies.md | 36 +++++++++++++++++++++++++++++++++ docs/_releases/v5.0.5/spies.md | 36 +++++++++++++++++++++++++++++++++ docs/_releases/v5.0.6/spies.md | 36 +++++++++++++++++++++++++++++++++ docs/_releases/v5.0.7/spies.md | 36 +++++++++++++++++++++++++++++++++ docs/_releases/v5.0.8/spies.md | 36 +++++++++++++++++++++++++++++++++ docs/_releases/v5.0.9/spies.md | 36 +++++++++++++++++++++++++++++++++ docs/_releases/v5.1.0/spies.md | 36 +++++++++++++++++++++++++++++++++ docs/_releases/v6.0.0/spies.md | 36 +++++++++++++++++++++++++++++++++ docs/_releases/v6.0.1/spies.md | 36 +++++++++++++++++++++++++++++++++ docs/_releases/v6.1.0/spies.md | 36 +++++++++++++++++++++++++++++++++ docs/_releases/v6.1.1/spies.md | 36 +++++++++++++++++++++++++++++++++ docs/_releases/v6.1.2/spies.md | 36 +++++++++++++++++++++++++++++++++ docs/_releases/v6.1.3/spies.md | 36 +++++++++++++++++++++++++++++++++ docs/_releases/v6.1.4/spies.md | 36 +++++++++++++++++++++++++++++++++ docs/_releases/v6.1.5/spies.md | 36 +++++++++++++++++++++++++++++++++ docs/_releases/v6.1.6/spies.md | 36 +++++++++++++++++++++++++++++++++ docs/_releases/v6.2.0/spies.md | 36 +++++++++++++++++++++++++++++++++ docs/_releases/v6.3.0/spies.md | 36 +++++++++++++++++++++++++++++++++ docs/_releases/v6.3.1/spies.md | 36 +++++++++++++++++++++++++++++++++ docs/_releases/v6.3.2/spies.md | 36 +++++++++++++++++++++++++++++++++ docs/_releases/v6.3.3/spies.md | 36 +++++++++++++++++++++++++++++++++ docs/_releases/v6.3.4/spies.md | 36 +++++++++++++++++++++++++++++++++ docs/_releases/v6.3.5/spies.md | 36 +++++++++++++++++++++++++++++++++ docs/_releases/v7.0.0/spies.md | 36 +++++++++++++++++++++++++++++++++ docs/_releases/v7.1.0/spies.md | 36 +++++++++++++++++++++++++++++++++ docs/_releases/v7.1.1/spies.md | 36 +++++++++++++++++++++++++++++++++ docs/_releases/v7.2.0/spies.md | 36 +++++++++++++++++++++++++++++++++ docs/_releases/v7.2.1/spies.md | 36 +++++++++++++++++++++++++++++++++ docs/_releases/v7.2.2/spies.md | 36 +++++++++++++++++++++++++++++++++ docs/_releases/v7.2.3/spies.md | 36 +++++++++++++++++++++++++++++++++ 83 files changed, 2988 insertions(+) diff --git a/docs/_releases/latest/spies.md b/docs/_releases/latest/spies.md index 906837158..4df4743c0 100644 --- a/docs/_releases/latest/spies.md +++ b/docs/_releases/latest/spies.md @@ -60,6 +60,32 @@ all [calls][call]. The following is a slightly contrived example: } ``` +### Using a spy to wrap property getter and setter + +`sinon.spy(object, "property", ["get", "set"])` creates spies that wrap the +getters and setters for `object.property`. The spies will behave exactly like +the original getters and setters, but you will have access to data about all +[calls][call]. Example: + + +```javascript +var object = { + get test() { + return this.property; + }, + set test(value) { + this.property = value * 2; + } +}; + +var spy = sinon.spy(object, "test", ["get", "set"]); + +object.test = 42; +assert(spy.set.calledOnce); + +assert.equals(object.test, 84); +assert(spy.get.calledOnce); +``` ### Creating spies: `sinon.spy()` Method Signatures @@ -80,6 +106,16 @@ all [calls][call]. The following is a slightly contrived example: object.method.restore(). The returned spy is the function object which replaced the original method. spy === object.method. +
var spy = sinon.spy(object, "property", types);
+
+ Creates a spy for object.property descriptor and replaces the + original accessor methods (`get`, `set`) listed in the types + array with a spy. The spies act exactly like the original accessors in all + cases. The original accessors can be restored by calling + spy.restore(). The returned spy is the object which replaced + the original property descriptor. spy.get === + Object.getOwnPropertyDescriptor(object, 'property').get. +
diff --git a/docs/_releases/v1.17.6/spies.md b/docs/_releases/v1.17.6/spies.md index d1b8ddde9..0680c4668 100644 --- a/docs/_releases/v1.17.6/spies.md +++ b/docs/_releases/v1.17.6/spies.md @@ -60,6 +60,32 @@ all [calls][call]. The following is a slightly contrived example: } ``` +### Using a spy to wrap property getter and setter + +`sinon.spy(object, "property", ["get", "set"])` creates spies that wrap the +getters and setters for `object.property`. The spies will behave exactly like +the original getters and setters, but you will have access to data about all +[calls][call]. Example: + + +```javascript +var object = { + get test() { + return this.property; + }, + set test(value) { + this.property = value * 2; + } +}; + +var spy = sinon.spy(object, "test", ["get", "set"]); + +object.test = 42; +assert(spy.set.calledOnce); + +assert.equals(object.test, 84); +assert(spy.get.calledOnce); +``` ### Creating spies: `sinon.spy()` Method Signatures @@ -80,6 +106,16 @@ all [calls][call]. The following is a slightly contrived example: object.method.restore(). The returned spy is the function object which replaced the original method. spy === object.method. +
var spy = sinon.spy(object, "property", types);
+
+ Creates a spy for object.property descriptor and replaces the + original accessor methods (`get`, `set`) listed in the types + array with a spy. The spies act exactly like the original accessors in all + cases. The original accessors can be restored by calling + spy.restore(). The returned spy is the object which replaced + the original property descriptor. spy.get === + Object.getOwnPropertyDescriptor(object, 'property').get. +
diff --git a/docs/_releases/v1.17.7/spies.md b/docs/_releases/v1.17.7/spies.md index f85d97f64..e356a0812 100644 --- a/docs/_releases/v1.17.7/spies.md +++ b/docs/_releases/v1.17.7/spies.md @@ -60,6 +60,32 @@ all [calls][call]. The following is a slightly contrived example: } ``` +### Using a spy to wrap property getter and setter + +`sinon.spy(object, "property", ["get", "set"])` creates spies that wrap the +getters and setters for `object.property`. The spies will behave exactly like +the original getters and setters, but you will have access to data about all +[calls][call]. Example: + + +```javascript +var object = { + get test() { + return this.property; + }, + set test(value) { + this.property = value * 2; + } +}; + +var spy = sinon.spy(object, "test", ["get", "set"]); + +object.test = 42; +assert(spy.set.calledOnce); + +assert.equals(object.test, 84); +assert(spy.get.calledOnce); +``` ### Creating spies: `sinon.spy()` Method Signatures @@ -80,6 +106,16 @@ all [calls][call]. The following is a slightly contrived example: object.method.restore(). The returned spy is the function object which replaced the original method. spy === object.method. +
var spy = sinon.spy(object, "property", types);
+
+ Creates a spy for object.property descriptor and replaces the + original accessor methods (`get`, `set`) listed in the types + array with a spy. The spies act exactly like the original accessors in all + cases. The original accessors can be restored by calling + spy.restore(). The returned spy is the object which replaced + the original property descriptor. spy.get === + Object.getOwnPropertyDescriptor(object, 'property').get. +
diff --git a/docs/_releases/v2.0.0/spies.md b/docs/_releases/v2.0.0/spies.md index 132d96c10..84ee88606 100644 --- a/docs/_releases/v2.0.0/spies.md +++ b/docs/_releases/v2.0.0/spies.md @@ -60,6 +60,32 @@ all [calls][call]. The following is a slightly contrived example: } ``` +### Using a spy to wrap property getter and setter + +`sinon.spy(object, "property", ["get", "set"])` creates spies that wrap the +getters and setters for `object.property`. The spies will behave exactly like +the original getters and setters, but you will have access to data about all +[calls][call]. Example: + + +```javascript +var object = { + get test() { + return this.property; + }, + set test(value) { + this.property = value * 2; + } +}; + +var spy = sinon.spy(object, "test", ["get", "set"]); + +object.test = 42; +assert(spy.set.calledOnce); + +assert.equals(object.test, 84); +assert(spy.get.calledOnce); +``` ### Creating spies: `sinon.spy()` Method Signatures @@ -80,6 +106,16 @@ all [calls][call]. The following is a slightly contrived example: object.method.restore(). The returned spy is the function object which replaced the original method. spy === object.method. +
var spy = sinon.spy(object, "property", types);
+
+ Creates a spy for object.property descriptor and replaces the + original accessor methods (`get`, `set`) listed in the types + array with a spy. The spies act exactly like the original accessors in all + cases. The original accessors can be restored by calling + spy.restore(). The returned spy is the object which replaced + the original property descriptor. spy.get === + Object.getOwnPropertyDescriptor(object, 'property').get. +
diff --git a/docs/_releases/v2.1.0/spies.md b/docs/_releases/v2.1.0/spies.md index ab299b349..8f14526aa 100644 --- a/docs/_releases/v2.1.0/spies.md +++ b/docs/_releases/v2.1.0/spies.md @@ -60,6 +60,32 @@ all [calls][call]. The following is a slightly contrived example: } ``` +### Using a spy to wrap property getter and setter + +`sinon.spy(object, "property", ["get", "set"])` creates spies that wrap the +getters and setters for `object.property`. The spies will behave exactly like +the original getters and setters, but you will have access to data about all +[calls][call]. Example: + + +```javascript +var object = { + get test() { + return this.property; + }, + set test(value) { + this.property = value * 2; + } +}; + +var spy = sinon.spy(object, "test", ["get", "set"]); + +object.test = 42; +assert(spy.set.calledOnce); + +assert.equals(object.test, 84); +assert(spy.get.calledOnce); +``` ### Creating spies: `sinon.spy()` Method Signatures @@ -80,6 +106,16 @@ all [calls][call]. The following is a slightly contrived example: object.method.restore(). The returned spy is the function object which replaced the original method. spy === object.method. +
var spy = sinon.spy(object, "property", types);
+
+ Creates a spy for object.property descriptor and replaces the + original accessor methods (`get`, `set`) listed in the types + array with a spy. The spies act exactly like the original accessors in all + cases. The original accessors can be restored by calling + spy.restore(). The returned spy is the object which replaced + the original property descriptor. spy.get === + Object.getOwnPropertyDescriptor(object, 'property').get. +
diff --git a/docs/_releases/v2.2.0/spies.md b/docs/_releases/v2.2.0/spies.md index b1f5eaf95..07735519c 100644 --- a/docs/_releases/v2.2.0/spies.md +++ b/docs/_releases/v2.2.0/spies.md @@ -60,6 +60,32 @@ all [calls][call]. The following is a slightly contrived example: } ``` +### Using a spy to wrap property getter and setter + +`sinon.spy(object, "property", ["get", "set"])` creates spies that wrap the +getters and setters for `object.property`. The spies will behave exactly like +the original getters and setters, but you will have access to data about all +[calls][call]. Example: + + +```javascript +var object = { + get test() { + return this.property; + }, + set test(value) { + this.property = value * 2; + } +}; + +var spy = sinon.spy(object, "test", ["get", "set"]); + +object.test = 42; +assert(spy.set.calledOnce); + +assert.equals(object.test, 84); +assert(spy.get.calledOnce); +``` ### Creating spies: `sinon.spy()` Method Signatures @@ -80,6 +106,16 @@ all [calls][call]. The following is a slightly contrived example: object.method.restore(). The returned spy is the function object which replaced the original method. spy === object.method. +
var spy = sinon.spy(object, "property", types);
+
+ Creates a spy for object.property descriptor and replaces the + original accessor methods (`get`, `set`) listed in the types + array with a spy. The spies act exactly like the original accessors in all + cases. The original accessors can be restored by calling + spy.restore(). The returned spy is the object which replaced + the original property descriptor. spy.get === + Object.getOwnPropertyDescriptor(object, 'property').get. +
diff --git a/docs/_releases/v2.3.0/spies.md b/docs/_releases/v2.3.0/spies.md index 0e1bae578..e5f78806d 100644 --- a/docs/_releases/v2.3.0/spies.md +++ b/docs/_releases/v2.3.0/spies.md @@ -60,6 +60,32 @@ all [calls][call]. The following is a slightly contrived example: } ``` +### Using a spy to wrap property getter and setter + +`sinon.spy(object, "property", ["get", "set"])` creates spies that wrap the +getters and setters for `object.property`. The spies will behave exactly like +the original getters and setters, but you will have access to data about all +[calls][call]. Example: + + +```javascript +var object = { + get test() { + return this.property; + }, + set test(value) { + this.property = value * 2; + } +}; + +var spy = sinon.spy(object, "test", ["get", "set"]); + +object.test = 42; +assert(spy.set.calledOnce); + +assert.equals(object.test, 84); +assert(spy.get.calledOnce); +``` ### Creating spies: `sinon.spy()` Method Signatures @@ -80,6 +106,16 @@ all [calls][call]. The following is a slightly contrived example: object.method.restore(). The returned spy is the function object which replaced the original method. spy === object.method. +
var spy = sinon.spy(object, "property", types);
+
+ Creates a spy for object.property descriptor and replaces the + original accessor methods (`get`, `set`) listed in the types + array with a spy. The spies act exactly like the original accessors in all + cases. The original accessors can be restored by calling + spy.restore(). The returned spy is the object which replaced + the original property descriptor. spy.get === + Object.getOwnPropertyDescriptor(object, 'property').get. +
diff --git a/docs/_releases/v2.3.1/spies.md b/docs/_releases/v2.3.1/spies.md index b1f5eaf95..07735519c 100644 --- a/docs/_releases/v2.3.1/spies.md +++ b/docs/_releases/v2.3.1/spies.md @@ -60,6 +60,32 @@ all [calls][call]. The following is a slightly contrived example: } ``` +### Using a spy to wrap property getter and setter + +`sinon.spy(object, "property", ["get", "set"])` creates spies that wrap the +getters and setters for `object.property`. The spies will behave exactly like +the original getters and setters, but you will have access to data about all +[calls][call]. Example: + + +```javascript +var object = { + get test() { + return this.property; + }, + set test(value) { + this.property = value * 2; + } +}; + +var spy = sinon.spy(object, "test", ["get", "set"]); + +object.test = 42; +assert(spy.set.calledOnce); + +assert.equals(object.test, 84); +assert(spy.get.calledOnce); +``` ### Creating spies: `sinon.spy()` Method Signatures @@ -80,6 +106,16 @@ all [calls][call]. The following is a slightly contrived example: object.method.restore(). The returned spy is the function object which replaced the original method. spy === object.method. +
var spy = sinon.spy(object, "property", types);
+
+ Creates a spy for object.property descriptor and replaces the + original accessor methods (`get`, `set`) listed in the types + array with a spy. The spies act exactly like the original accessors in all + cases. The original accessors can be restored by calling + spy.restore(). The returned spy is the object which replaced + the original property descriptor. spy.get === + Object.getOwnPropertyDescriptor(object, 'property').get. +
diff --git a/docs/_releases/v2.3.2/spies.md b/docs/_releases/v2.3.2/spies.md index 0e1bae578..e5f78806d 100644 --- a/docs/_releases/v2.3.2/spies.md +++ b/docs/_releases/v2.3.2/spies.md @@ -60,6 +60,32 @@ all [calls][call]. The following is a slightly contrived example: } ``` +### Using a spy to wrap property getter and setter + +`sinon.spy(object, "property", ["get", "set"])` creates spies that wrap the +getters and setters for `object.property`. The spies will behave exactly like +the original getters and setters, but you will have access to data about all +[calls][call]. Example: + + +```javascript +var object = { + get test() { + return this.property; + }, + set test(value) { + this.property = value * 2; + } +}; + +var spy = sinon.spy(object, "test", ["get", "set"]); + +object.test = 42; +assert(spy.set.calledOnce); + +assert.equals(object.test, 84); +assert(spy.get.calledOnce); +``` ### Creating spies: `sinon.spy()` Method Signatures @@ -80,6 +106,16 @@ all [calls][call]. The following is a slightly contrived example: object.method.restore(). The returned spy is the function object which replaced the original method. spy === object.method. +
var spy = sinon.spy(object, "property", types);
+
+ Creates a spy for object.property descriptor and replaces the + original accessor methods (`get`, `set`) listed in the types + array with a spy. The spies act exactly like the original accessors in all + cases. The original accessors can be restored by calling + spy.restore(). The returned spy is the object which replaced + the original property descriptor. spy.get === + Object.getOwnPropertyDescriptor(object, 'property').get. +
diff --git a/docs/_releases/v2.3.3/spies.md b/docs/_releases/v2.3.3/spies.md index b1f5eaf95..07735519c 100644 --- a/docs/_releases/v2.3.3/spies.md +++ b/docs/_releases/v2.3.3/spies.md @@ -60,6 +60,32 @@ all [calls][call]. The following is a slightly contrived example: } ``` +### Using a spy to wrap property getter and setter + +`sinon.spy(object, "property", ["get", "set"])` creates spies that wrap the +getters and setters for `object.property`. The spies will behave exactly like +the original getters and setters, but you will have access to data about all +[calls][call]. Example: + + +```javascript +var object = { + get test() { + return this.property; + }, + set test(value) { + this.property = value * 2; + } +}; + +var spy = sinon.spy(object, "test", ["get", "set"]); + +object.test = 42; +assert(spy.set.calledOnce); + +assert.equals(object.test, 84); +assert(spy.get.calledOnce); +``` ### Creating spies: `sinon.spy()` Method Signatures @@ -80,6 +106,16 @@ all [calls][call]. The following is a slightly contrived example: object.method.restore(). The returned spy is the function object which replaced the original method. spy === object.method. +
var spy = sinon.spy(object, "property", types);
+
+ Creates a spy for object.property descriptor and replaces the + original accessor methods (`get`, `set`) listed in the types + array with a spy. The spies act exactly like the original accessors in all + cases. The original accessors can be restored by calling + spy.restore(). The returned spy is the object which replaced + the original property descriptor. spy.get === + Object.getOwnPropertyDescriptor(object, 'property').get. +
diff --git a/docs/_releases/v2.3.4/spies.md b/docs/_releases/v2.3.4/spies.md index 0e1bae578..e5f78806d 100644 --- a/docs/_releases/v2.3.4/spies.md +++ b/docs/_releases/v2.3.4/spies.md @@ -60,6 +60,32 @@ all [calls][call]. The following is a slightly contrived example: } ``` +### Using a spy to wrap property getter and setter + +`sinon.spy(object, "property", ["get", "set"])` creates spies that wrap the +getters and setters for `object.property`. The spies will behave exactly like +the original getters and setters, but you will have access to data about all +[calls][call]. Example: + + +```javascript +var object = { + get test() { + return this.property; + }, + set test(value) { + this.property = value * 2; + } +}; + +var spy = sinon.spy(object, "test", ["get", "set"]); + +object.test = 42; +assert(spy.set.calledOnce); + +assert.equals(object.test, 84); +assert(spy.get.calledOnce); +``` ### Creating spies: `sinon.spy()` Method Signatures @@ -80,6 +106,16 @@ all [calls][call]. The following is a slightly contrived example: object.method.restore(). The returned spy is the function object which replaced the original method. spy === object.method. +
var spy = sinon.spy(object, "property", types);
+
+ Creates a spy for object.property descriptor and replaces the + original accessor methods (`get`, `set`) listed in the types + array with a spy. The spies act exactly like the original accessors in all + cases. The original accessors can be restored by calling + spy.restore(). The returned spy is the object which replaced + the original property descriptor. spy.get === + Object.getOwnPropertyDescriptor(object, 'property').get. +
diff --git a/docs/_releases/v2.3.5/spies.md b/docs/_releases/v2.3.5/spies.md index b1f5eaf95..07735519c 100644 --- a/docs/_releases/v2.3.5/spies.md +++ b/docs/_releases/v2.3.5/spies.md @@ -60,6 +60,32 @@ all [calls][call]. The following is a slightly contrived example: } ``` +### Using a spy to wrap property getter and setter + +`sinon.spy(object, "property", ["get", "set"])` creates spies that wrap the +getters and setters for `object.property`. The spies will behave exactly like +the original getters and setters, but you will have access to data about all +[calls][call]. Example: + + +```javascript +var object = { + get test() { + return this.property; + }, + set test(value) { + this.property = value * 2; + } +}; + +var spy = sinon.spy(object, "test", ["get", "set"]); + +object.test = 42; +assert(spy.set.calledOnce); + +assert.equals(object.test, 84); +assert(spy.get.calledOnce); +``` ### Creating spies: `sinon.spy()` Method Signatures @@ -80,6 +106,16 @@ all [calls][call]. The following is a slightly contrived example: object.method.restore(). The returned spy is the function object which replaced the original method. spy === object.method. +
var spy = sinon.spy(object, "property", types);
+
+ Creates a spy for object.property descriptor and replaces the + original accessor methods (`get`, `set`) listed in the types + array with a spy. The spies act exactly like the original accessors in all + cases. The original accessors can be restored by calling + spy.restore(). The returned spy is the object which replaced + the original property descriptor. spy.get === + Object.getOwnPropertyDescriptor(object, 'property').get. +
diff --git a/docs/_releases/v2.3.6/spies.md b/docs/_releases/v2.3.6/spies.md index 0e1bae578..e5f78806d 100644 --- a/docs/_releases/v2.3.6/spies.md +++ b/docs/_releases/v2.3.6/spies.md @@ -60,6 +60,32 @@ all [calls][call]. The following is a slightly contrived example: } ``` +### Using a spy to wrap property getter and setter + +`sinon.spy(object, "property", ["get", "set"])` creates spies that wrap the +getters and setters for `object.property`. The spies will behave exactly like +the original getters and setters, but you will have access to data about all +[calls][call]. Example: + + +```javascript +var object = { + get test() { + return this.property; + }, + set test(value) { + this.property = value * 2; + } +}; + +var spy = sinon.spy(object, "test", ["get", "set"]); + +object.test = 42; +assert(spy.set.calledOnce); + +assert.equals(object.test, 84); +assert(spy.get.calledOnce); +``` ### Creating spies: `sinon.spy()` Method Signatures @@ -80,6 +106,16 @@ all [calls][call]. The following is a slightly contrived example: object.method.restore(). The returned spy is the function object which replaced the original method. spy === object.method. +
var spy = sinon.spy(object, "property", types);
+
+ Creates a spy for object.property descriptor and replaces the + original accessor methods (`get`, `set`) listed in the types + array with a spy. The spies act exactly like the original accessors in all + cases. The original accessors can be restored by calling + spy.restore(). The returned spy is the object which replaced + the original property descriptor. spy.get === + Object.getOwnPropertyDescriptor(object, 'property').get. +
diff --git a/docs/_releases/v2.3.7/spies.md b/docs/_releases/v2.3.7/spies.md index b1f5eaf95..07735519c 100644 --- a/docs/_releases/v2.3.7/spies.md +++ b/docs/_releases/v2.3.7/spies.md @@ -60,6 +60,32 @@ all [calls][call]. The following is a slightly contrived example: } ``` +### Using a spy to wrap property getter and setter + +`sinon.spy(object, "property", ["get", "set"])` creates spies that wrap the +getters and setters for `object.property`. The spies will behave exactly like +the original getters and setters, but you will have access to data about all +[calls][call]. Example: + + +```javascript +var object = { + get test() { + return this.property; + }, + set test(value) { + this.property = value * 2; + } +}; + +var spy = sinon.spy(object, "test", ["get", "set"]); + +object.test = 42; +assert(spy.set.calledOnce); + +assert.equals(object.test, 84); +assert(spy.get.calledOnce); +``` ### Creating spies: `sinon.spy()` Method Signatures @@ -80,6 +106,16 @@ all [calls][call]. The following is a slightly contrived example: object.method.restore(). The returned spy is the function object which replaced the original method. spy === object.method. +
var spy = sinon.spy(object, "property", types);
+
+ Creates a spy for object.property descriptor and replaces the + original accessor methods (`get`, `set`) listed in the types + array with a spy. The spies act exactly like the original accessors in all + cases. The original accessors can be restored by calling + spy.restore(). The returned spy is the object which replaced + the original property descriptor. spy.get === + Object.getOwnPropertyDescriptor(object, 'property').get. +
diff --git a/docs/_releases/v2.3.8/spies.md b/docs/_releases/v2.3.8/spies.md index 256c73bf0..5f5ddabe7 100644 --- a/docs/_releases/v2.3.8/spies.md +++ b/docs/_releases/v2.3.8/spies.md @@ -60,6 +60,32 @@ all [calls][call]. The following is a slightly contrived example: } ``` +### Using a spy to wrap property getter and setter + +`sinon.spy(object, "property", ["get", "set"])` creates spies that wrap the +getters and setters for `object.property`. The spies will behave exactly like +the original getters and setters, but you will have access to data about all +[calls][call]. Example: + + +```javascript +var object = { + get test() { + return this.property; + }, + set test(value) { + this.property = value * 2; + } +}; + +var spy = sinon.spy(object, "test", ["get", "set"]); + +object.test = 42; +assert(spy.set.calledOnce); + +assert.equals(object.test, 84); +assert(spy.get.calledOnce); +``` ### Creating spies: `sinon.spy()` Method Signatures @@ -80,6 +106,16 @@ all [calls][call]. The following is a slightly contrived example: object.method.restore(). The returned spy is the function object which replaced the original method. spy === object.method. +
var spy = sinon.spy(object, "property", types);
+
+ Creates a spy for object.property descriptor and replaces the + original accessor methods (`get`, `set`) listed in the types + array with a spy. The spies act exactly like the original accessors in all + cases. The original accessors can be restored by calling + spy.restore(). The returned spy is the object which replaced + the original property descriptor. spy.get === + Object.getOwnPropertyDescriptor(object, 'property').get. +
diff --git a/docs/_releases/v2.4.0/spies.md b/docs/_releases/v2.4.0/spies.md index b1f5eaf95..07735519c 100644 --- a/docs/_releases/v2.4.0/spies.md +++ b/docs/_releases/v2.4.0/spies.md @@ -60,6 +60,32 @@ all [calls][call]. The following is a slightly contrived example: } ``` +### Using a spy to wrap property getter and setter + +`sinon.spy(object, "property", ["get", "set"])` creates spies that wrap the +getters and setters for `object.property`. The spies will behave exactly like +the original getters and setters, but you will have access to data about all +[calls][call]. Example: + + +```javascript +var object = { + get test() { + return this.property; + }, + set test(value) { + this.property = value * 2; + } +}; + +var spy = sinon.spy(object, "test", ["get", "set"]); + +object.test = 42; +assert(spy.set.calledOnce); + +assert.equals(object.test, 84); +assert(spy.get.calledOnce); +``` ### Creating spies: `sinon.spy()` Method Signatures @@ -80,6 +106,16 @@ all [calls][call]. The following is a slightly contrived example: object.method.restore(). The returned spy is the function object which replaced the original method. spy === object.method. +
var spy = sinon.spy(object, "property", types);
+
+ Creates a spy for object.property descriptor and replaces the + original accessor methods (`get`, `set`) listed in the types + array with a spy. The spies act exactly like the original accessors in all + cases. The original accessors can be restored by calling + spy.restore(). The returned spy is the object which replaced + the original property descriptor. spy.get === + Object.getOwnPropertyDescriptor(object, 'property').get. +
diff --git a/docs/_releases/v2.4.1/spies.md b/docs/_releases/v2.4.1/spies.md index b1f5eaf95..07735519c 100644 --- a/docs/_releases/v2.4.1/spies.md +++ b/docs/_releases/v2.4.1/spies.md @@ -60,6 +60,32 @@ all [calls][call]. The following is a slightly contrived example: } ``` +### Using a spy to wrap property getter and setter + +`sinon.spy(object, "property", ["get", "set"])` creates spies that wrap the +getters and setters for `object.property`. The spies will behave exactly like +the original getters and setters, but you will have access to data about all +[calls][call]. Example: + + +```javascript +var object = { + get test() { + return this.property; + }, + set test(value) { + this.property = value * 2; + } +}; + +var spy = sinon.spy(object, "test", ["get", "set"]); + +object.test = 42; +assert(spy.set.calledOnce); + +assert.equals(object.test, 84); +assert(spy.get.calledOnce); +``` ### Creating spies: `sinon.spy()` Method Signatures @@ -80,6 +106,16 @@ all [calls][call]. The following is a slightly contrived example: object.method.restore(). The returned spy is the function object which replaced the original method. spy === object.method. +
var spy = sinon.spy(object, "property", types);
+
+ Creates a spy for object.property descriptor and replaces the + original accessor methods (`get`, `set`) listed in the types + array with a spy. The spies act exactly like the original accessors in all + cases. The original accessors can be restored by calling + spy.restore(). The returned spy is the object which replaced + the original property descriptor. spy.get === + Object.getOwnPropertyDescriptor(object, 'property').get. +
diff --git a/docs/_releases/v3.0.0/spies.md b/docs/_releases/v3.0.0/spies.md index 256c73bf0..5f5ddabe7 100644 --- a/docs/_releases/v3.0.0/spies.md +++ b/docs/_releases/v3.0.0/spies.md @@ -60,6 +60,32 @@ all [calls][call]. The following is a slightly contrived example: } ``` +### Using a spy to wrap property getter and setter + +`sinon.spy(object, "property", ["get", "set"])` creates spies that wrap the +getters and setters for `object.property`. The spies will behave exactly like +the original getters and setters, but you will have access to data about all +[calls][call]. Example: + + +```javascript +var object = { + get test() { + return this.property; + }, + set test(value) { + this.property = value * 2; + } +}; + +var spy = sinon.spy(object, "test", ["get", "set"]); + +object.test = 42; +assert(spy.set.calledOnce); + +assert.equals(object.test, 84); +assert(spy.get.calledOnce); +``` ### Creating spies: `sinon.spy()` Method Signatures @@ -80,6 +106,16 @@ all [calls][call]. The following is a slightly contrived example: object.method.restore(). The returned spy is the function object which replaced the original method. spy === object.method. +
var spy = sinon.spy(object, "property", types);
+
+ Creates a spy for object.property descriptor and replaces the + original accessor methods (`get`, `set`) listed in the types + array with a spy. The spies act exactly like the original accessors in all + cases. The original accessors can be restored by calling + spy.restore(). The returned spy is the object which replaced + the original property descriptor. spy.get === + Object.getOwnPropertyDescriptor(object, 'property').get. +
diff --git a/docs/_releases/v3.1.0/spies.md b/docs/_releases/v3.1.0/spies.md index b1f5eaf95..07735519c 100644 --- a/docs/_releases/v3.1.0/spies.md +++ b/docs/_releases/v3.1.0/spies.md @@ -60,6 +60,32 @@ all [calls][call]. The following is a slightly contrived example: } ``` +### Using a spy to wrap property getter and setter + +`sinon.spy(object, "property", ["get", "set"])` creates spies that wrap the +getters and setters for `object.property`. The spies will behave exactly like +the original getters and setters, but you will have access to data about all +[calls][call]. Example: + + +```javascript +var object = { + get test() { + return this.property; + }, + set test(value) { + this.property = value * 2; + } +}; + +var spy = sinon.spy(object, "test", ["get", "set"]); + +object.test = 42; +assert(spy.set.calledOnce); + +assert.equals(object.test, 84); +assert(spy.get.calledOnce); +``` ### Creating spies: `sinon.spy()` Method Signatures @@ -80,6 +106,16 @@ all [calls][call]. The following is a slightly contrived example: object.method.restore(). The returned spy is the function object which replaced the original method. spy === object.method. +
var spy = sinon.spy(object, "property", types);
+
+ Creates a spy for object.property descriptor and replaces the + original accessor methods (`get`, `set`) listed in the types + array with a spy. The spies act exactly like the original accessors in all + cases. The original accessors can be restored by calling + spy.restore(). The returned spy is the object which replaced + the original property descriptor. spy.get === + Object.getOwnPropertyDescriptor(object, 'property').get. +
diff --git a/docs/_releases/v3.2.0/spies.md b/docs/_releases/v3.2.0/spies.md index b1f5eaf95..07735519c 100644 --- a/docs/_releases/v3.2.0/spies.md +++ b/docs/_releases/v3.2.0/spies.md @@ -60,6 +60,32 @@ all [calls][call]. The following is a slightly contrived example: } ``` +### Using a spy to wrap property getter and setter + +`sinon.spy(object, "property", ["get", "set"])` creates spies that wrap the +getters and setters for `object.property`. The spies will behave exactly like +the original getters and setters, but you will have access to data about all +[calls][call]. Example: + + +```javascript +var object = { + get test() { + return this.property; + }, + set test(value) { + this.property = value * 2; + } +}; + +var spy = sinon.spy(object, "test", ["get", "set"]); + +object.test = 42; +assert(spy.set.calledOnce); + +assert.equals(object.test, 84); +assert(spy.get.calledOnce); +``` ### Creating spies: `sinon.spy()` Method Signatures @@ -80,6 +106,16 @@ all [calls][call]. The following is a slightly contrived example: object.method.restore(). The returned spy is the function object which replaced the original method. spy === object.method. +
var spy = sinon.spy(object, "property", types);
+
+ Creates a spy for object.property descriptor and replaces the + original accessor methods (`get`, `set`) listed in the types + array with a spy. The spies act exactly like the original accessors in all + cases. The original accessors can be restored by calling + spy.restore(). The returned spy is the object which replaced + the original property descriptor. spy.get === + Object.getOwnPropertyDescriptor(object, 'property').get. +
diff --git a/docs/_releases/v3.2.1/spies.md b/docs/_releases/v3.2.1/spies.md index b1f5eaf95..07735519c 100644 --- a/docs/_releases/v3.2.1/spies.md +++ b/docs/_releases/v3.2.1/spies.md @@ -60,6 +60,32 @@ all [calls][call]. The following is a slightly contrived example: } ``` +### Using a spy to wrap property getter and setter + +`sinon.spy(object, "property", ["get", "set"])` creates spies that wrap the +getters and setters for `object.property`. The spies will behave exactly like +the original getters and setters, but you will have access to data about all +[calls][call]. Example: + + +```javascript +var object = { + get test() { + return this.property; + }, + set test(value) { + this.property = value * 2; + } +}; + +var spy = sinon.spy(object, "test", ["get", "set"]); + +object.test = 42; +assert(spy.set.calledOnce); + +assert.equals(object.test, 84); +assert(spy.get.calledOnce); +``` ### Creating spies: `sinon.spy()` Method Signatures @@ -80,6 +106,16 @@ all [calls][call]. The following is a slightly contrived example: object.method.restore(). The returned spy is the function object which replaced the original method. spy === object.method. +
var spy = sinon.spy(object, "property", types);
+
+ Creates a spy for object.property descriptor and replaces the + original accessor methods (`get`, `set`) listed in the types + array with a spy. The spies act exactly like the original accessors in all + cases. The original accessors can be restored by calling + spy.restore(). The returned spy is the object which replaced + the original property descriptor. spy.get === + Object.getOwnPropertyDescriptor(object, 'property').get. +
diff --git a/docs/_releases/v3.3.0/spies.md b/docs/_releases/v3.3.0/spies.md index b1f5eaf95..07735519c 100644 --- a/docs/_releases/v3.3.0/spies.md +++ b/docs/_releases/v3.3.0/spies.md @@ -60,6 +60,32 @@ all [calls][call]. The following is a slightly contrived example: } ``` +### Using a spy to wrap property getter and setter + +`sinon.spy(object, "property", ["get", "set"])` creates spies that wrap the +getters and setters for `object.property`. The spies will behave exactly like +the original getters and setters, but you will have access to data about all +[calls][call]. Example: + + +```javascript +var object = { + get test() { + return this.property; + }, + set test(value) { + this.property = value * 2; + } +}; + +var spy = sinon.spy(object, "test", ["get", "set"]); + +object.test = 42; +assert(spy.set.calledOnce); + +assert.equals(object.test, 84); +assert(spy.get.calledOnce); +``` ### Creating spies: `sinon.spy()` Method Signatures @@ -80,6 +106,16 @@ all [calls][call]. The following is a slightly contrived example: object.method.restore(). The returned spy is the function object which replaced the original method. spy === object.method. +
var spy = sinon.spy(object, "property", types);
+
+ Creates a spy for object.property descriptor and replaces the + original accessor methods (`get`, `set`) listed in the types + array with a spy. The spies act exactly like the original accessors in all + cases. The original accessors can be restored by calling + spy.restore(). The returned spy is the object which replaced + the original property descriptor. spy.get === + Object.getOwnPropertyDescriptor(object, 'property').get. +
diff --git a/docs/_releases/v4.0.0/spies.md b/docs/_releases/v4.0.0/spies.md index b1f5eaf95..07735519c 100644 --- a/docs/_releases/v4.0.0/spies.md +++ b/docs/_releases/v4.0.0/spies.md @@ -60,6 +60,32 @@ all [calls][call]. The following is a slightly contrived example: } ``` +### Using a spy to wrap property getter and setter + +`sinon.spy(object, "property", ["get", "set"])` creates spies that wrap the +getters and setters for `object.property`. The spies will behave exactly like +the original getters and setters, but you will have access to data about all +[calls][call]. Example: + + +```javascript +var object = { + get test() { + return this.property; + }, + set test(value) { + this.property = value * 2; + } +}; + +var spy = sinon.spy(object, "test", ["get", "set"]); + +object.test = 42; +assert(spy.set.calledOnce); + +assert.equals(object.test, 84); +assert(spy.get.calledOnce); +``` ### Creating spies: `sinon.spy()` Method Signatures @@ -80,6 +106,16 @@ all [calls][call]. The following is a slightly contrived example: object.method.restore(). The returned spy is the function object which replaced the original method. spy === object.method. +
var spy = sinon.spy(object, "property", types);
+
+ Creates a spy for object.property descriptor and replaces the + original accessor methods (`get`, `set`) listed in the types + array with a spy. The spies act exactly like the original accessors in all + cases. The original accessors can be restored by calling + spy.restore(). The returned spy is the object which replaced + the original property descriptor. spy.get === + Object.getOwnPropertyDescriptor(object, 'property').get. +
diff --git a/docs/_releases/v4.0.1/spies.md b/docs/_releases/v4.0.1/spies.md index b1f5eaf95..07735519c 100644 --- a/docs/_releases/v4.0.1/spies.md +++ b/docs/_releases/v4.0.1/spies.md @@ -60,6 +60,32 @@ all [calls][call]. The following is a slightly contrived example: } ``` +### Using a spy to wrap property getter and setter + +`sinon.spy(object, "property", ["get", "set"])` creates spies that wrap the +getters and setters for `object.property`. The spies will behave exactly like +the original getters and setters, but you will have access to data about all +[calls][call]. Example: + + +```javascript +var object = { + get test() { + return this.property; + }, + set test(value) { + this.property = value * 2; + } +}; + +var spy = sinon.spy(object, "test", ["get", "set"]); + +object.test = 42; +assert(spy.set.calledOnce); + +assert.equals(object.test, 84); +assert(spy.get.calledOnce); +``` ### Creating spies: `sinon.spy()` Method Signatures @@ -80,6 +106,16 @@ all [calls][call]. The following is a slightly contrived example: object.method.restore(). The returned spy is the function object which replaced the original method. spy === object.method. +
var spy = sinon.spy(object, "property", types);
+
+ Creates a spy for object.property descriptor and replaces the + original accessor methods (`get`, `set`) listed in the types + array with a spy. The spies act exactly like the original accessors in all + cases. The original accessors can be restored by calling + spy.restore(). The returned spy is the object which replaced + the original property descriptor. spy.get === + Object.getOwnPropertyDescriptor(object, 'property').get. +
diff --git a/docs/_releases/v4.0.2/spies.md b/docs/_releases/v4.0.2/spies.md index b1f5eaf95..07735519c 100644 --- a/docs/_releases/v4.0.2/spies.md +++ b/docs/_releases/v4.0.2/spies.md @@ -60,6 +60,32 @@ all [calls][call]. The following is a slightly contrived example: } ``` +### Using a spy to wrap property getter and setter + +`sinon.spy(object, "property", ["get", "set"])` creates spies that wrap the +getters and setters for `object.property`. The spies will behave exactly like +the original getters and setters, but you will have access to data about all +[calls][call]. Example: + + +```javascript +var object = { + get test() { + return this.property; + }, + set test(value) { + this.property = value * 2; + } +}; + +var spy = sinon.spy(object, "test", ["get", "set"]); + +object.test = 42; +assert(spy.set.calledOnce); + +assert.equals(object.test, 84); +assert(spy.get.calledOnce); +``` ### Creating spies: `sinon.spy()` Method Signatures @@ -80,6 +106,16 @@ all [calls][call]. The following is a slightly contrived example: object.method.restore(). The returned spy is the function object which replaced the original method. spy === object.method. +
var spy = sinon.spy(object, "property", types);
+
+ Creates a spy for object.property descriptor and replaces the + original accessor methods (`get`, `set`) listed in the types + array with a spy. The spies act exactly like the original accessors in all + cases. The original accessors can be restored by calling + spy.restore(). The returned spy is the object which replaced + the original property descriptor. spy.get === + Object.getOwnPropertyDescriptor(object, 'property').get. +
diff --git a/docs/_releases/v4.1.0/spies.md b/docs/_releases/v4.1.0/spies.md index b1f5eaf95..07735519c 100644 --- a/docs/_releases/v4.1.0/spies.md +++ b/docs/_releases/v4.1.0/spies.md @@ -60,6 +60,32 @@ all [calls][call]. The following is a slightly contrived example: } ``` +### Using a spy to wrap property getter and setter + +`sinon.spy(object, "property", ["get", "set"])` creates spies that wrap the +getters and setters for `object.property`. The spies will behave exactly like +the original getters and setters, but you will have access to data about all +[calls][call]. Example: + + +```javascript +var object = { + get test() { + return this.property; + }, + set test(value) { + this.property = value * 2; + } +}; + +var spy = sinon.spy(object, "test", ["get", "set"]); + +object.test = 42; +assert(spy.set.calledOnce); + +assert.equals(object.test, 84); +assert(spy.get.calledOnce); +``` ### Creating spies: `sinon.spy()` Method Signatures @@ -80,6 +106,16 @@ all [calls][call]. The following is a slightly contrived example: object.method.restore(). The returned spy is the function object which replaced the original method. spy === object.method. +
var spy = sinon.spy(object, "property", types);
+
+ Creates a spy for object.property descriptor and replaces the + original accessor methods (`get`, `set`) listed in the types + array with a spy. The spies act exactly like the original accessors in all + cases. The original accessors can be restored by calling + spy.restore(). The returned spy is the object which replaced + the original property descriptor. spy.get === + Object.getOwnPropertyDescriptor(object, 'property').get. +
diff --git a/docs/_releases/v4.1.1/spies.md b/docs/_releases/v4.1.1/spies.md index b1f5eaf95..07735519c 100644 --- a/docs/_releases/v4.1.1/spies.md +++ b/docs/_releases/v4.1.1/spies.md @@ -60,6 +60,32 @@ all [calls][call]. The following is a slightly contrived example: } ``` +### Using a spy to wrap property getter and setter + +`sinon.spy(object, "property", ["get", "set"])` creates spies that wrap the +getters and setters for `object.property`. The spies will behave exactly like +the original getters and setters, but you will have access to data about all +[calls][call]. Example: + + +```javascript +var object = { + get test() { + return this.property; + }, + set test(value) { + this.property = value * 2; + } +}; + +var spy = sinon.spy(object, "test", ["get", "set"]); + +object.test = 42; +assert(spy.set.calledOnce); + +assert.equals(object.test, 84); +assert(spy.get.calledOnce); +``` ### Creating spies: `sinon.spy()` Method Signatures @@ -80,6 +106,16 @@ all [calls][call]. The following is a slightly contrived example: object.method.restore(). The returned spy is the function object which replaced the original method. spy === object.method. +
var spy = sinon.spy(object, "property", types);
+
+ Creates a spy for object.property descriptor and replaces the + original accessor methods (`get`, `set`) listed in the types + array with a spy. The spies act exactly like the original accessors in all + cases. The original accessors can be restored by calling + spy.restore(). The returned spy is the object which replaced + the original property descriptor. spy.get === + Object.getOwnPropertyDescriptor(object, 'property').get. +
diff --git a/docs/_releases/v4.1.2/spies.md b/docs/_releases/v4.1.2/spies.md index b1f5eaf95..07735519c 100644 --- a/docs/_releases/v4.1.2/spies.md +++ b/docs/_releases/v4.1.2/spies.md @@ -60,6 +60,32 @@ all [calls][call]. The following is a slightly contrived example: } ``` +### Using a spy to wrap property getter and setter + +`sinon.spy(object, "property", ["get", "set"])` creates spies that wrap the +getters and setters for `object.property`. The spies will behave exactly like +the original getters and setters, but you will have access to data about all +[calls][call]. Example: + + +```javascript +var object = { + get test() { + return this.property; + }, + set test(value) { + this.property = value * 2; + } +}; + +var spy = sinon.spy(object, "test", ["get", "set"]); + +object.test = 42; +assert(spy.set.calledOnce); + +assert.equals(object.test, 84); +assert(spy.get.calledOnce); +``` ### Creating spies: `sinon.spy()` Method Signatures @@ -80,6 +106,16 @@ all [calls][call]. The following is a slightly contrived example: object.method.restore(). The returned spy is the function object which replaced the original method. spy === object.method. +
var spy = sinon.spy(object, "property", types);
+
+ Creates a spy for object.property descriptor and replaces the + original accessor methods (`get`, `set`) listed in the types + array with a spy. The spies act exactly like the original accessors in all + cases. The original accessors can be restored by calling + spy.restore(). The returned spy is the object which replaced + the original property descriptor. spy.get === + Object.getOwnPropertyDescriptor(object, 'property').get. +
diff --git a/docs/_releases/v4.1.3/spies.md b/docs/_releases/v4.1.3/spies.md index b1f5eaf95..07735519c 100644 --- a/docs/_releases/v4.1.3/spies.md +++ b/docs/_releases/v4.1.3/spies.md @@ -60,6 +60,32 @@ all [calls][call]. The following is a slightly contrived example: } ``` +### Using a spy to wrap property getter and setter + +`sinon.spy(object, "property", ["get", "set"])` creates spies that wrap the +getters and setters for `object.property`. The spies will behave exactly like +the original getters and setters, but you will have access to data about all +[calls][call]. Example: + + +```javascript +var object = { + get test() { + return this.property; + }, + set test(value) { + this.property = value * 2; + } +}; + +var spy = sinon.spy(object, "test", ["get", "set"]); + +object.test = 42; +assert(spy.set.calledOnce); + +assert.equals(object.test, 84); +assert(spy.get.calledOnce); +``` ### Creating spies: `sinon.spy()` Method Signatures @@ -80,6 +106,16 @@ all [calls][call]. The following is a slightly contrived example: object.method.restore(). The returned spy is the function object which replaced the original method. spy === object.method. +
var spy = sinon.spy(object, "property", types);
+
+ Creates a spy for object.property descriptor and replaces the + original accessor methods (`get`, `set`) listed in the types + array with a spy. The spies act exactly like the original accessors in all + cases. The original accessors can be restored by calling + spy.restore(). The returned spy is the object which replaced + the original property descriptor. spy.get === + Object.getOwnPropertyDescriptor(object, 'property').get. +
diff --git a/docs/_releases/v4.1.4/spies.md b/docs/_releases/v4.1.4/spies.md index b1f5eaf95..07735519c 100644 --- a/docs/_releases/v4.1.4/spies.md +++ b/docs/_releases/v4.1.4/spies.md @@ -60,6 +60,32 @@ all [calls][call]. The following is a slightly contrived example: } ``` +### Using a spy to wrap property getter and setter + +`sinon.spy(object, "property", ["get", "set"])` creates spies that wrap the +getters and setters for `object.property`. The spies will behave exactly like +the original getters and setters, but you will have access to data about all +[calls][call]. Example: + + +```javascript +var object = { + get test() { + return this.property; + }, + set test(value) { + this.property = value * 2; + } +}; + +var spy = sinon.spy(object, "test", ["get", "set"]); + +object.test = 42; +assert(spy.set.calledOnce); + +assert.equals(object.test, 84); +assert(spy.get.calledOnce); +``` ### Creating spies: `sinon.spy()` Method Signatures @@ -80,6 +106,16 @@ all [calls][call]. The following is a slightly contrived example: object.method.restore(). The returned spy is the function object which replaced the original method. spy === object.method. +
var spy = sinon.spy(object, "property", types);
+
+ Creates a spy for object.property descriptor and replaces the + original accessor methods (`get`, `set`) listed in the types + array with a spy. The spies act exactly like the original accessors in all + cases. The original accessors can be restored by calling + spy.restore(). The returned spy is the object which replaced + the original property descriptor. spy.get === + Object.getOwnPropertyDescriptor(object, 'property').get. +
diff --git a/docs/_releases/v4.1.5/spies.md b/docs/_releases/v4.1.5/spies.md index b1f5eaf95..07735519c 100644 --- a/docs/_releases/v4.1.5/spies.md +++ b/docs/_releases/v4.1.5/spies.md @@ -60,6 +60,32 @@ all [calls][call]. The following is a slightly contrived example: } ``` +### Using a spy to wrap property getter and setter + +`sinon.spy(object, "property", ["get", "set"])` creates spies that wrap the +getters and setters for `object.property`. The spies will behave exactly like +the original getters and setters, but you will have access to data about all +[calls][call]. Example: + + +```javascript +var object = { + get test() { + return this.property; + }, + set test(value) { + this.property = value * 2; + } +}; + +var spy = sinon.spy(object, "test", ["get", "set"]); + +object.test = 42; +assert(spy.set.calledOnce); + +assert.equals(object.test, 84); +assert(spy.get.calledOnce); +``` ### Creating spies: `sinon.spy()` Method Signatures @@ -80,6 +106,16 @@ all [calls][call]. The following is a slightly contrived example: object.method.restore(). The returned spy is the function object which replaced the original method. spy === object.method. +
var spy = sinon.spy(object, "property", types);
+
+ Creates a spy for object.property descriptor and replaces the + original accessor methods (`get`, `set`) listed in the types + array with a spy. The spies act exactly like the original accessors in all + cases. The original accessors can be restored by calling + spy.restore(). The returned spy is the object which replaced + the original property descriptor. spy.get === + Object.getOwnPropertyDescriptor(object, 'property').get. +
diff --git a/docs/_releases/v4.1.6/spies.md b/docs/_releases/v4.1.6/spies.md index b1f5eaf95..07735519c 100644 --- a/docs/_releases/v4.1.6/spies.md +++ b/docs/_releases/v4.1.6/spies.md @@ -60,6 +60,32 @@ all [calls][call]. The following is a slightly contrived example: } ``` +### Using a spy to wrap property getter and setter + +`sinon.spy(object, "property", ["get", "set"])` creates spies that wrap the +getters and setters for `object.property`. The spies will behave exactly like +the original getters and setters, but you will have access to data about all +[calls][call]. Example: + + +```javascript +var object = { + get test() { + return this.property; + }, + set test(value) { + this.property = value * 2; + } +}; + +var spy = sinon.spy(object, "test", ["get", "set"]); + +object.test = 42; +assert(spy.set.calledOnce); + +assert.equals(object.test, 84); +assert(spy.get.calledOnce); +``` ### Creating spies: `sinon.spy()` Method Signatures @@ -80,6 +106,16 @@ all [calls][call]. The following is a slightly contrived example: object.method.restore(). The returned spy is the function object which replaced the original method. spy === object.method. +
var spy = sinon.spy(object, "property", types);
+
+ Creates a spy for object.property descriptor and replaces the + original accessor methods (`get`, `set`) listed in the types + array with a spy. The spies act exactly like the original accessors in all + cases. The original accessors can be restored by calling + spy.restore(). The returned spy is the object which replaced + the original property descriptor. spy.get === + Object.getOwnPropertyDescriptor(object, 'property').get. +
diff --git a/docs/_releases/v4.2.0/spies.md b/docs/_releases/v4.2.0/spies.md index b1f5eaf95..07735519c 100644 --- a/docs/_releases/v4.2.0/spies.md +++ b/docs/_releases/v4.2.0/spies.md @@ -60,6 +60,32 @@ all [calls][call]. The following is a slightly contrived example: } ``` +### Using a spy to wrap property getter and setter + +`sinon.spy(object, "property", ["get", "set"])` creates spies that wrap the +getters and setters for `object.property`. The spies will behave exactly like +the original getters and setters, but you will have access to data about all +[calls][call]. Example: + + +```javascript +var object = { + get test() { + return this.property; + }, + set test(value) { + this.property = value * 2; + } +}; + +var spy = sinon.spy(object, "test", ["get", "set"]); + +object.test = 42; +assert(spy.set.calledOnce); + +assert.equals(object.test, 84); +assert(spy.get.calledOnce); +``` ### Creating spies: `sinon.spy()` Method Signatures @@ -80,6 +106,16 @@ all [calls][call]. The following is a slightly contrived example: object.method.restore(). The returned spy is the function object which replaced the original method. spy === object.method. +
var spy = sinon.spy(object, "property", types);
+
+ Creates a spy for object.property descriptor and replaces the + original accessor methods (`get`, `set`) listed in the types + array with a spy. The spies act exactly like the original accessors in all + cases. The original accessors can be restored by calling + spy.restore(). The returned spy is the object which replaced + the original property descriptor. spy.get === + Object.getOwnPropertyDescriptor(object, 'property').get. +
diff --git a/docs/_releases/v4.2.1/spies.md b/docs/_releases/v4.2.1/spies.md index b1f5eaf95..07735519c 100644 --- a/docs/_releases/v4.2.1/spies.md +++ b/docs/_releases/v4.2.1/spies.md @@ -60,6 +60,32 @@ all [calls][call]. The following is a slightly contrived example: } ``` +### Using a spy to wrap property getter and setter + +`sinon.spy(object, "property", ["get", "set"])` creates spies that wrap the +getters and setters for `object.property`. The spies will behave exactly like +the original getters and setters, but you will have access to data about all +[calls][call]. Example: + + +```javascript +var object = { + get test() { + return this.property; + }, + set test(value) { + this.property = value * 2; + } +}; + +var spy = sinon.spy(object, "test", ["get", "set"]); + +object.test = 42; +assert(spy.set.calledOnce); + +assert.equals(object.test, 84); +assert(spy.get.calledOnce); +``` ### Creating spies: `sinon.spy()` Method Signatures @@ -80,6 +106,16 @@ all [calls][call]. The following is a slightly contrived example: object.method.restore(). The returned spy is the function object which replaced the original method. spy === object.method. +
var spy = sinon.spy(object, "property", types);
+
+ Creates a spy for object.property descriptor and replaces the + original accessor methods (`get`, `set`) listed in the types + array with a spy. The spies act exactly like the original accessors in all + cases. The original accessors can be restored by calling + spy.restore(). The returned spy is the object which replaced + the original property descriptor. spy.get === + Object.getOwnPropertyDescriptor(object, 'property').get. +
diff --git a/docs/_releases/v4.2.2/spies.md b/docs/_releases/v4.2.2/spies.md index b1f5eaf95..07735519c 100644 --- a/docs/_releases/v4.2.2/spies.md +++ b/docs/_releases/v4.2.2/spies.md @@ -60,6 +60,32 @@ all [calls][call]. The following is a slightly contrived example: } ``` +### Using a spy to wrap property getter and setter + +`sinon.spy(object, "property", ["get", "set"])` creates spies that wrap the +getters and setters for `object.property`. The spies will behave exactly like +the original getters and setters, but you will have access to data about all +[calls][call]. Example: + + +```javascript +var object = { + get test() { + return this.property; + }, + set test(value) { + this.property = value * 2; + } +}; + +var spy = sinon.spy(object, "test", ["get", "set"]); + +object.test = 42; +assert(spy.set.calledOnce); + +assert.equals(object.test, 84); +assert(spy.get.calledOnce); +``` ### Creating spies: `sinon.spy()` Method Signatures @@ -80,6 +106,16 @@ all [calls][call]. The following is a slightly contrived example: object.method.restore(). The returned spy is the function object which replaced the original method. spy === object.method. +
var spy = sinon.spy(object, "property", types);
+
+ Creates a spy for object.property descriptor and replaces the + original accessor methods (`get`, `set`) listed in the types + array with a spy. The spies act exactly like the original accessors in all + cases. The original accessors can be restored by calling + spy.restore(). The returned spy is the object which replaced + the original property descriptor. spy.get === + Object.getOwnPropertyDescriptor(object, 'property').get. +
diff --git a/docs/_releases/v4.2.3/spies.md b/docs/_releases/v4.2.3/spies.md index b1f5eaf95..07735519c 100644 --- a/docs/_releases/v4.2.3/spies.md +++ b/docs/_releases/v4.2.3/spies.md @@ -60,6 +60,32 @@ all [calls][call]. The following is a slightly contrived example: } ``` +### Using a spy to wrap property getter and setter + +`sinon.spy(object, "property", ["get", "set"])` creates spies that wrap the +getters and setters for `object.property`. The spies will behave exactly like +the original getters and setters, but you will have access to data about all +[calls][call]. Example: + + +```javascript +var object = { + get test() { + return this.property; + }, + set test(value) { + this.property = value * 2; + } +}; + +var spy = sinon.spy(object, "test", ["get", "set"]); + +object.test = 42; +assert(spy.set.calledOnce); + +assert.equals(object.test, 84); +assert(spy.get.calledOnce); +``` ### Creating spies: `sinon.spy()` Method Signatures @@ -80,6 +106,16 @@ all [calls][call]. The following is a slightly contrived example: object.method.restore(). The returned spy is the function object which replaced the original method. spy === object.method. +
var spy = sinon.spy(object, "property", types);
+
+ Creates a spy for object.property descriptor and replaces the + original accessor methods (`get`, `set`) listed in the types + array with a spy. The spies act exactly like the original accessors in all + cases. The original accessors can be restored by calling + spy.restore(). The returned spy is the object which replaced + the original property descriptor. spy.get === + Object.getOwnPropertyDescriptor(object, 'property').get. +
diff --git a/docs/_releases/v4.3.0/spies.md b/docs/_releases/v4.3.0/spies.md index 3bcf20bc6..2b757b9c8 100644 --- a/docs/_releases/v4.3.0/spies.md +++ b/docs/_releases/v4.3.0/spies.md @@ -60,6 +60,32 @@ all [calls][call]. The following is a slightly contrived example: } ``` +### Using a spy to wrap property getter and setter + +`sinon.spy(object, "property", ["get", "set"])` creates spies that wrap the +getters and setters for `object.property`. The spies will behave exactly like +the original getters and setters, but you will have access to data about all +[calls][call]. Example: + + +```javascript +var object = { + get test() { + return this.property; + }, + set test(value) { + this.property = value * 2; + } +}; + +var spy = sinon.spy(object, "test", ["get", "set"]); + +object.test = 42; +assert(spy.set.calledOnce); + +assert.equals(object.test, 84); +assert(spy.get.calledOnce); +``` ### Creating spies: `sinon.spy()` Method Signatures @@ -80,6 +106,16 @@ all [calls][call]. The following is a slightly contrived example: object.method.restore(). The returned spy is the function object which replaced the original method. spy === object.method. +
var spy = sinon.spy(object, "property", types);
+
+ Creates a spy for object.property descriptor and replaces the + original accessor methods (`get`, `set`) listed in the types + array with a spy. The spies act exactly like the original accessors in all + cases. The original accessors can be restored by calling + spy.restore(). The returned spy is the object which replaced + the original property descriptor. spy.get === + Object.getOwnPropertyDescriptor(object, 'property').get. +
diff --git a/docs/_releases/v4.4.0/spies.md b/docs/_releases/v4.4.0/spies.md index 3bcf20bc6..2b757b9c8 100644 --- a/docs/_releases/v4.4.0/spies.md +++ b/docs/_releases/v4.4.0/spies.md @@ -60,6 +60,32 @@ all [calls][call]. The following is a slightly contrived example: } ``` +### Using a spy to wrap property getter and setter + +`sinon.spy(object, "property", ["get", "set"])` creates spies that wrap the +getters and setters for `object.property`. The spies will behave exactly like +the original getters and setters, but you will have access to data about all +[calls][call]. Example: + + +```javascript +var object = { + get test() { + return this.property; + }, + set test(value) { + this.property = value * 2; + } +}; + +var spy = sinon.spy(object, "test", ["get", "set"]); + +object.test = 42; +assert(spy.set.calledOnce); + +assert.equals(object.test, 84); +assert(spy.get.calledOnce); +``` ### Creating spies: `sinon.spy()` Method Signatures @@ -80,6 +106,16 @@ all [calls][call]. The following is a slightly contrived example: object.method.restore(). The returned spy is the function object which replaced the original method. spy === object.method. +
var spy = sinon.spy(object, "property", types);
+
+ Creates a spy for object.property descriptor and replaces the + original accessor methods (`get`, `set`) listed in the types + array with a spy. The spies act exactly like the original accessors in all + cases. The original accessors can be restored by calling + spy.restore(). The returned spy is the object which replaced + the original property descriptor. spy.get === + Object.getOwnPropertyDescriptor(object, 'property').get. +
diff --git a/docs/_releases/v4.4.1/spies.md b/docs/_releases/v4.4.1/spies.md index 3bcf20bc6..2b757b9c8 100644 --- a/docs/_releases/v4.4.1/spies.md +++ b/docs/_releases/v4.4.1/spies.md @@ -60,6 +60,32 @@ all [calls][call]. The following is a slightly contrived example: } ``` +### Using a spy to wrap property getter and setter + +`sinon.spy(object, "property", ["get", "set"])` creates spies that wrap the +getters and setters for `object.property`. The spies will behave exactly like +the original getters and setters, but you will have access to data about all +[calls][call]. Example: + + +```javascript +var object = { + get test() { + return this.property; + }, + set test(value) { + this.property = value * 2; + } +}; + +var spy = sinon.spy(object, "test", ["get", "set"]); + +object.test = 42; +assert(spy.set.calledOnce); + +assert.equals(object.test, 84); +assert(spy.get.calledOnce); +``` ### Creating spies: `sinon.spy()` Method Signatures @@ -80,6 +106,16 @@ all [calls][call]. The following is a slightly contrived example: object.method.restore(). The returned spy is the function object which replaced the original method. spy === object.method. +
var spy = sinon.spy(object, "property", types);
+
+ Creates a spy for object.property descriptor and replaces the + original accessor methods (`get`, `set`) listed in the types + array with a spy. The spies act exactly like the original accessors in all + cases. The original accessors can be restored by calling + spy.restore(). The returned spy is the object which replaced + the original property descriptor. spy.get === + Object.getOwnPropertyDescriptor(object, 'property').get. +
diff --git a/docs/_releases/v4.4.10/spies.md b/docs/_releases/v4.4.10/spies.md index 39bce5da9..a5ff84f90 100644 --- a/docs/_releases/v4.4.10/spies.md +++ b/docs/_releases/v4.4.10/spies.md @@ -60,6 +60,32 @@ all [calls][call]. The following is a slightly contrived example: } ``` +### Using a spy to wrap property getter and setter + +`sinon.spy(object, "property", ["get", "set"])` creates spies that wrap the +getters and setters for `object.property`. The spies will behave exactly like +the original getters and setters, but you will have access to data about all +[calls][call]. Example: + + +```javascript +var object = { + get test() { + return this.property; + }, + set test(value) { + this.property = value * 2; + } +}; + +var spy = sinon.spy(object, "test", ["get", "set"]); + +object.test = 42; +assert(spy.set.calledOnce); + +assert.equals(object.test, 84); +assert(spy.get.calledOnce); +``` ### Creating spies: `sinon.spy()` Method Signatures @@ -80,6 +106,16 @@ all [calls][call]. The following is a slightly contrived example: object.method.restore(). The returned spy is the function object which replaced the original method. spy === object.method. +
var spy = sinon.spy(object, "property", types);
+
+ Creates a spy for object.property descriptor and replaces the + original accessor methods (`get`, `set`) listed in the types + array with a spy. The spies act exactly like the original accessors in all + cases. The original accessors can be restored by calling + spy.restore(). The returned spy is the object which replaced + the original property descriptor. spy.get === + Object.getOwnPropertyDescriptor(object, 'property').get. +
diff --git a/docs/_releases/v4.4.2/spies.md b/docs/_releases/v4.4.2/spies.md index 0f11948d6..e433d5efc 100644 --- a/docs/_releases/v4.4.2/spies.md +++ b/docs/_releases/v4.4.2/spies.md @@ -60,6 +60,32 @@ all [calls][call]. The following is a slightly contrived example: } ``` +### Using a spy to wrap property getter and setter + +`sinon.spy(object, "property", ["get", "set"])` creates spies that wrap the +getters and setters for `object.property`. The spies will behave exactly like +the original getters and setters, but you will have access to data about all +[calls][call]. Example: + + +```javascript +var object = { + get test() { + return this.property; + }, + set test(value) { + this.property = value * 2; + } +}; + +var spy = sinon.spy(object, "test", ["get", "set"]); + +object.test = 42; +assert(spy.set.calledOnce); + +assert.equals(object.test, 84); +assert(spy.get.calledOnce); +``` ### Creating spies: `sinon.spy()` Method Signatures @@ -80,6 +106,16 @@ all [calls][call]. The following is a slightly contrived example: object.method.restore(). The returned spy is the function object which replaced the original method. spy === object.method. +
var spy = sinon.spy(object, "property", types);
+
+ Creates a spy for object.property descriptor and replaces the + original accessor methods (`get`, `set`) listed in the types + array with a spy. The spies act exactly like the original accessors in all + cases. The original accessors can be restored by calling + spy.restore(). The returned spy is the object which replaced + the original property descriptor. spy.get === + Object.getOwnPropertyDescriptor(object, 'property').get. +
diff --git a/docs/_releases/v4.4.3/spies.md b/docs/_releases/v4.4.3/spies.md index 39bce5da9..a5ff84f90 100644 --- a/docs/_releases/v4.4.3/spies.md +++ b/docs/_releases/v4.4.3/spies.md @@ -60,6 +60,32 @@ all [calls][call]. The following is a slightly contrived example: } ``` +### Using a spy to wrap property getter and setter + +`sinon.spy(object, "property", ["get", "set"])` creates spies that wrap the +getters and setters for `object.property`. The spies will behave exactly like +the original getters and setters, but you will have access to data about all +[calls][call]. Example: + + +```javascript +var object = { + get test() { + return this.property; + }, + set test(value) { + this.property = value * 2; + } +}; + +var spy = sinon.spy(object, "test", ["get", "set"]); + +object.test = 42; +assert(spy.set.calledOnce); + +assert.equals(object.test, 84); +assert(spy.get.calledOnce); +``` ### Creating spies: `sinon.spy()` Method Signatures @@ -80,6 +106,16 @@ all [calls][call]. The following is a slightly contrived example: object.method.restore(). The returned spy is the function object which replaced the original method. spy === object.method. +
var spy = sinon.spy(object, "property", types);
+
+ Creates a spy for object.property descriptor and replaces the + original accessor methods (`get`, `set`) listed in the types + array with a spy. The spies act exactly like the original accessors in all + cases. The original accessors can be restored by calling + spy.restore(). The returned spy is the object which replaced + the original property descriptor. spy.get === + Object.getOwnPropertyDescriptor(object, 'property').get. +
diff --git a/docs/_releases/v4.4.4/spies.md b/docs/_releases/v4.4.4/spies.md index 39bce5da9..a5ff84f90 100644 --- a/docs/_releases/v4.4.4/spies.md +++ b/docs/_releases/v4.4.4/spies.md @@ -60,6 +60,32 @@ all [calls][call]. The following is a slightly contrived example: } ``` +### Using a spy to wrap property getter and setter + +`sinon.spy(object, "property", ["get", "set"])` creates spies that wrap the +getters and setters for `object.property`. The spies will behave exactly like +the original getters and setters, but you will have access to data about all +[calls][call]. Example: + + +```javascript +var object = { + get test() { + return this.property; + }, + set test(value) { + this.property = value * 2; + } +}; + +var spy = sinon.spy(object, "test", ["get", "set"]); + +object.test = 42; +assert(spy.set.calledOnce); + +assert.equals(object.test, 84); +assert(spy.get.calledOnce); +``` ### Creating spies: `sinon.spy()` Method Signatures @@ -80,6 +106,16 @@ all [calls][call]. The following is a slightly contrived example: object.method.restore(). The returned spy is the function object which replaced the original method. spy === object.method. +
var spy = sinon.spy(object, "property", types);
+
+ Creates a spy for object.property descriptor and replaces the + original accessor methods (`get`, `set`) listed in the types + array with a spy. The spies act exactly like the original accessors in all + cases. The original accessors can be restored by calling + spy.restore(). The returned spy is the object which replaced + the original property descriptor. spy.get === + Object.getOwnPropertyDescriptor(object, 'property').get. +
diff --git a/docs/_releases/v4.4.5/spies.md b/docs/_releases/v4.4.5/spies.md index 39bce5da9..a5ff84f90 100644 --- a/docs/_releases/v4.4.5/spies.md +++ b/docs/_releases/v4.4.5/spies.md @@ -60,6 +60,32 @@ all [calls][call]. The following is a slightly contrived example: } ``` +### Using a spy to wrap property getter and setter + +`sinon.spy(object, "property", ["get", "set"])` creates spies that wrap the +getters and setters for `object.property`. The spies will behave exactly like +the original getters and setters, but you will have access to data about all +[calls][call]. Example: + + +```javascript +var object = { + get test() { + return this.property; + }, + set test(value) { + this.property = value * 2; + } +}; + +var spy = sinon.spy(object, "test", ["get", "set"]); + +object.test = 42; +assert(spy.set.calledOnce); + +assert.equals(object.test, 84); +assert(spy.get.calledOnce); +``` ### Creating spies: `sinon.spy()` Method Signatures @@ -80,6 +106,16 @@ all [calls][call]. The following is a slightly contrived example: object.method.restore(). The returned spy is the function object which replaced the original method. spy === object.method. +
var spy = sinon.spy(object, "property", types);
+
+ Creates a spy for object.property descriptor and replaces the + original accessor methods (`get`, `set`) listed in the types + array with a spy. The spies act exactly like the original accessors in all + cases. The original accessors can be restored by calling + spy.restore(). The returned spy is the object which replaced + the original property descriptor. spy.get === + Object.getOwnPropertyDescriptor(object, 'property').get. +
diff --git a/docs/_releases/v4.4.6/spies.md b/docs/_releases/v4.4.6/spies.md index 39bce5da9..a5ff84f90 100644 --- a/docs/_releases/v4.4.6/spies.md +++ b/docs/_releases/v4.4.6/spies.md @@ -60,6 +60,32 @@ all [calls][call]. The following is a slightly contrived example: } ``` +### Using a spy to wrap property getter and setter + +`sinon.spy(object, "property", ["get", "set"])` creates spies that wrap the +getters and setters for `object.property`. The spies will behave exactly like +the original getters and setters, but you will have access to data about all +[calls][call]. Example: + + +```javascript +var object = { + get test() { + return this.property; + }, + set test(value) { + this.property = value * 2; + } +}; + +var spy = sinon.spy(object, "test", ["get", "set"]); + +object.test = 42; +assert(spy.set.calledOnce); + +assert.equals(object.test, 84); +assert(spy.get.calledOnce); +``` ### Creating spies: `sinon.spy()` Method Signatures @@ -80,6 +106,16 @@ all [calls][call]. The following is a slightly contrived example: object.method.restore(). The returned spy is the function object which replaced the original method. spy === object.method. +
var spy = sinon.spy(object, "property", types);
+
+ Creates a spy for object.property descriptor and replaces the + original accessor methods (`get`, `set`) listed in the types + array with a spy. The spies act exactly like the original accessors in all + cases. The original accessors can be restored by calling + spy.restore(). The returned spy is the object which replaced + the original property descriptor. spy.get === + Object.getOwnPropertyDescriptor(object, 'property').get. +
diff --git a/docs/_releases/v4.4.7/spies.md b/docs/_releases/v4.4.7/spies.md index 39bce5da9..a5ff84f90 100644 --- a/docs/_releases/v4.4.7/spies.md +++ b/docs/_releases/v4.4.7/spies.md @@ -60,6 +60,32 @@ all [calls][call]. The following is a slightly contrived example: } ``` +### Using a spy to wrap property getter and setter + +`sinon.spy(object, "property", ["get", "set"])` creates spies that wrap the +getters and setters for `object.property`. The spies will behave exactly like +the original getters and setters, but you will have access to data about all +[calls][call]. Example: + + +```javascript +var object = { + get test() { + return this.property; + }, + set test(value) { + this.property = value * 2; + } +}; + +var spy = sinon.spy(object, "test", ["get", "set"]); + +object.test = 42; +assert(spy.set.calledOnce); + +assert.equals(object.test, 84); +assert(spy.get.calledOnce); +``` ### Creating spies: `sinon.spy()` Method Signatures @@ -80,6 +106,16 @@ all [calls][call]. The following is a slightly contrived example: object.method.restore(). The returned spy is the function object which replaced the original method. spy === object.method. +
var spy = sinon.spy(object, "property", types);
+
+ Creates a spy for object.property descriptor and replaces the + original accessor methods (`get`, `set`) listed in the types + array with a spy. The spies act exactly like the original accessors in all + cases. The original accessors can be restored by calling + spy.restore(). The returned spy is the object which replaced + the original property descriptor. spy.get === + Object.getOwnPropertyDescriptor(object, 'property').get. +
diff --git a/docs/_releases/v4.4.8/spies.md b/docs/_releases/v4.4.8/spies.md index 39bce5da9..a5ff84f90 100644 --- a/docs/_releases/v4.4.8/spies.md +++ b/docs/_releases/v4.4.8/spies.md @@ -60,6 +60,32 @@ all [calls][call]. The following is a slightly contrived example: } ``` +### Using a spy to wrap property getter and setter + +`sinon.spy(object, "property", ["get", "set"])` creates spies that wrap the +getters and setters for `object.property`. The spies will behave exactly like +the original getters and setters, but you will have access to data about all +[calls][call]. Example: + + +```javascript +var object = { + get test() { + return this.property; + }, + set test(value) { + this.property = value * 2; + } +}; + +var spy = sinon.spy(object, "test", ["get", "set"]); + +object.test = 42; +assert(spy.set.calledOnce); + +assert.equals(object.test, 84); +assert(spy.get.calledOnce); +``` ### Creating spies: `sinon.spy()` Method Signatures @@ -80,6 +106,16 @@ all [calls][call]. The following is a slightly contrived example: object.method.restore(). The returned spy is the function object which replaced the original method. spy === object.method. +
var spy = sinon.spy(object, "property", types);
+
+ Creates a spy for object.property descriptor and replaces the + original accessor methods (`get`, `set`) listed in the types + array with a spy. The spies act exactly like the original accessors in all + cases. The original accessors can be restored by calling + spy.restore(). The returned spy is the object which replaced + the original property descriptor. spy.get === + Object.getOwnPropertyDescriptor(object, 'property').get. +
diff --git a/docs/_releases/v4.4.9/spies.md b/docs/_releases/v4.4.9/spies.md index 39bce5da9..a5ff84f90 100644 --- a/docs/_releases/v4.4.9/spies.md +++ b/docs/_releases/v4.4.9/spies.md @@ -60,6 +60,32 @@ all [calls][call]. The following is a slightly contrived example: } ``` +### Using a spy to wrap property getter and setter + +`sinon.spy(object, "property", ["get", "set"])` creates spies that wrap the +getters and setters for `object.property`. The spies will behave exactly like +the original getters and setters, but you will have access to data about all +[calls][call]. Example: + + +```javascript +var object = { + get test() { + return this.property; + }, + set test(value) { + this.property = value * 2; + } +}; + +var spy = sinon.spy(object, "test", ["get", "set"]); + +object.test = 42; +assert(spy.set.calledOnce); + +assert.equals(object.test, 84); +assert(spy.get.calledOnce); +``` ### Creating spies: `sinon.spy()` Method Signatures @@ -80,6 +106,16 @@ all [calls][call]. The following is a slightly contrived example: object.method.restore(). The returned spy is the function object which replaced the original method. spy === object.method. +
var spy = sinon.spy(object, "property", types);
+
+ Creates a spy for object.property descriptor and replaces the + original accessor methods (`get`, `set`) listed in the types + array with a spy. The spies act exactly like the original accessors in all + cases. The original accessors can be restored by calling + spy.restore(). The returned spy is the object which replaced + the original property descriptor. spy.get === + Object.getOwnPropertyDescriptor(object, 'property').get. +
diff --git a/docs/_releases/v4.5.0/spies.md b/docs/_releases/v4.5.0/spies.md index 39bce5da9..a5ff84f90 100644 --- a/docs/_releases/v4.5.0/spies.md +++ b/docs/_releases/v4.5.0/spies.md @@ -60,6 +60,32 @@ all [calls][call]. The following is a slightly contrived example: } ``` +### Using a spy to wrap property getter and setter + +`sinon.spy(object, "property", ["get", "set"])` creates spies that wrap the +getters and setters for `object.property`. The spies will behave exactly like +the original getters and setters, but you will have access to data about all +[calls][call]. Example: + + +```javascript +var object = { + get test() { + return this.property; + }, + set test(value) { + this.property = value * 2; + } +}; + +var spy = sinon.spy(object, "test", ["get", "set"]); + +object.test = 42; +assert(spy.set.calledOnce); + +assert.equals(object.test, 84); +assert(spy.get.calledOnce); +``` ### Creating spies: `sinon.spy()` Method Signatures @@ -80,6 +106,16 @@ all [calls][call]. The following is a slightly contrived example: object.method.restore(). The returned spy is the function object which replaced the original method. spy === object.method. +
var spy = sinon.spy(object, "property", types);
+
+ Creates a spy for object.property descriptor and replaces the + original accessor methods (`get`, `set`) listed in the types + array with a spy. The spies act exactly like the original accessors in all + cases. The original accessors can be restored by calling + spy.restore(). The returned spy is the object which replaced + the original property descriptor. spy.get === + Object.getOwnPropertyDescriptor(object, 'property').get. +
diff --git a/docs/_releases/v5.0.1/spies.md b/docs/_releases/v5.0.1/spies.md index 39bce5da9..a5ff84f90 100644 --- a/docs/_releases/v5.0.1/spies.md +++ b/docs/_releases/v5.0.1/spies.md @@ -60,6 +60,32 @@ all [calls][call]. The following is a slightly contrived example: } ``` +### Using a spy to wrap property getter and setter + +`sinon.spy(object, "property", ["get", "set"])` creates spies that wrap the +getters and setters for `object.property`. The spies will behave exactly like +the original getters and setters, but you will have access to data about all +[calls][call]. Example: + + +```javascript +var object = { + get test() { + return this.property; + }, + set test(value) { + this.property = value * 2; + } +}; + +var spy = sinon.spy(object, "test", ["get", "set"]); + +object.test = 42; +assert(spy.set.calledOnce); + +assert.equals(object.test, 84); +assert(spy.get.calledOnce); +``` ### Creating spies: `sinon.spy()` Method Signatures @@ -80,6 +106,16 @@ all [calls][call]. The following is a slightly contrived example: object.method.restore(). The returned spy is the function object which replaced the original method. spy === object.method. +
var spy = sinon.spy(object, "property", types);
+
+ Creates a spy for object.property descriptor and replaces the + original accessor methods (`get`, `set`) listed in the types + array with a spy. The spies act exactly like the original accessors in all + cases. The original accessors can be restored by calling + spy.restore(). The returned spy is the object which replaced + the original property descriptor. spy.get === + Object.getOwnPropertyDescriptor(object, 'property').get. +
diff --git a/docs/_releases/v5.0.10/spies.md b/docs/_releases/v5.0.10/spies.md index 39bce5da9..a5ff84f90 100644 --- a/docs/_releases/v5.0.10/spies.md +++ b/docs/_releases/v5.0.10/spies.md @@ -60,6 +60,32 @@ all [calls][call]. The following is a slightly contrived example: } ``` +### Using a spy to wrap property getter and setter + +`sinon.spy(object, "property", ["get", "set"])` creates spies that wrap the +getters and setters for `object.property`. The spies will behave exactly like +the original getters and setters, but you will have access to data about all +[calls][call]. Example: + + +```javascript +var object = { + get test() { + return this.property; + }, + set test(value) { + this.property = value * 2; + } +}; + +var spy = sinon.spy(object, "test", ["get", "set"]); + +object.test = 42; +assert(spy.set.calledOnce); + +assert.equals(object.test, 84); +assert(spy.get.calledOnce); +``` ### Creating spies: `sinon.spy()` Method Signatures @@ -80,6 +106,16 @@ all [calls][call]. The following is a slightly contrived example: object.method.restore(). The returned spy is the function object which replaced the original method. spy === object.method. +
var spy = sinon.spy(object, "property", types);
+
+ Creates a spy for object.property descriptor and replaces the + original accessor methods (`get`, `set`) listed in the types + array with a spy. The spies act exactly like the original accessors in all + cases. The original accessors can be restored by calling + spy.restore(). The returned spy is the object which replaced + the original property descriptor. spy.get === + Object.getOwnPropertyDescriptor(object, 'property').get. +
diff --git a/docs/_releases/v5.0.2/spies.md b/docs/_releases/v5.0.2/spies.md index 39bce5da9..a5ff84f90 100644 --- a/docs/_releases/v5.0.2/spies.md +++ b/docs/_releases/v5.0.2/spies.md @@ -60,6 +60,32 @@ all [calls][call]. The following is a slightly contrived example: } ``` +### Using a spy to wrap property getter and setter + +`sinon.spy(object, "property", ["get", "set"])` creates spies that wrap the +getters and setters for `object.property`. The spies will behave exactly like +the original getters and setters, but you will have access to data about all +[calls][call]. Example: + + +```javascript +var object = { + get test() { + return this.property; + }, + set test(value) { + this.property = value * 2; + } +}; + +var spy = sinon.spy(object, "test", ["get", "set"]); + +object.test = 42; +assert(spy.set.calledOnce); + +assert.equals(object.test, 84); +assert(spy.get.calledOnce); +``` ### Creating spies: `sinon.spy()` Method Signatures @@ -80,6 +106,16 @@ all [calls][call]. The following is a slightly contrived example: object.method.restore(). The returned spy is the function object which replaced the original method. spy === object.method. +
var spy = sinon.spy(object, "property", types);
+
+ Creates a spy for object.property descriptor and replaces the + original accessor methods (`get`, `set`) listed in the types + array with a spy. The spies act exactly like the original accessors in all + cases. The original accessors can be restored by calling + spy.restore(). The returned spy is the object which replaced + the original property descriptor. spy.get === + Object.getOwnPropertyDescriptor(object, 'property').get. +
diff --git a/docs/_releases/v5.0.3/spies.md b/docs/_releases/v5.0.3/spies.md index 39bce5da9..a5ff84f90 100644 --- a/docs/_releases/v5.0.3/spies.md +++ b/docs/_releases/v5.0.3/spies.md @@ -60,6 +60,32 @@ all [calls][call]. The following is a slightly contrived example: } ``` +### Using a spy to wrap property getter and setter + +`sinon.spy(object, "property", ["get", "set"])` creates spies that wrap the +getters and setters for `object.property`. The spies will behave exactly like +the original getters and setters, but you will have access to data about all +[calls][call]. Example: + + +```javascript +var object = { + get test() { + return this.property; + }, + set test(value) { + this.property = value * 2; + } +}; + +var spy = sinon.spy(object, "test", ["get", "set"]); + +object.test = 42; +assert(spy.set.calledOnce); + +assert.equals(object.test, 84); +assert(spy.get.calledOnce); +``` ### Creating spies: `sinon.spy()` Method Signatures @@ -80,6 +106,16 @@ all [calls][call]. The following is a slightly contrived example: object.method.restore(). The returned spy is the function object which replaced the original method. spy === object.method. +
var spy = sinon.spy(object, "property", types);
+
+ Creates a spy for object.property descriptor and replaces the + original accessor methods (`get`, `set`) listed in the types + array with a spy. The spies act exactly like the original accessors in all + cases. The original accessors can be restored by calling + spy.restore(). The returned spy is the object which replaced + the original property descriptor. spy.get === + Object.getOwnPropertyDescriptor(object, 'property').get. +
diff --git a/docs/_releases/v5.0.4/spies.md b/docs/_releases/v5.0.4/spies.md index 39bce5da9..a5ff84f90 100644 --- a/docs/_releases/v5.0.4/spies.md +++ b/docs/_releases/v5.0.4/spies.md @@ -60,6 +60,32 @@ all [calls][call]. The following is a slightly contrived example: } ``` +### Using a spy to wrap property getter and setter + +`sinon.spy(object, "property", ["get", "set"])` creates spies that wrap the +getters and setters for `object.property`. The spies will behave exactly like +the original getters and setters, but you will have access to data about all +[calls][call]. Example: + + +```javascript +var object = { + get test() { + return this.property; + }, + set test(value) { + this.property = value * 2; + } +}; + +var spy = sinon.spy(object, "test", ["get", "set"]); + +object.test = 42; +assert(spy.set.calledOnce); + +assert.equals(object.test, 84); +assert(spy.get.calledOnce); +``` ### Creating spies: `sinon.spy()` Method Signatures @@ -80,6 +106,16 @@ all [calls][call]. The following is a slightly contrived example: object.method.restore(). The returned spy is the function object which replaced the original method. spy === object.method. +
var spy = sinon.spy(object, "property", types);
+
+ Creates a spy for object.property descriptor and replaces the + original accessor methods (`get`, `set`) listed in the types + array with a spy. The spies act exactly like the original accessors in all + cases. The original accessors can be restored by calling + spy.restore(). The returned spy is the object which replaced + the original property descriptor. spy.get === + Object.getOwnPropertyDescriptor(object, 'property').get. +
diff --git a/docs/_releases/v5.0.5/spies.md b/docs/_releases/v5.0.5/spies.md index 39bce5da9..a5ff84f90 100644 --- a/docs/_releases/v5.0.5/spies.md +++ b/docs/_releases/v5.0.5/spies.md @@ -60,6 +60,32 @@ all [calls][call]. The following is a slightly contrived example: } ``` +### Using a spy to wrap property getter and setter + +`sinon.spy(object, "property", ["get", "set"])` creates spies that wrap the +getters and setters for `object.property`. The spies will behave exactly like +the original getters and setters, but you will have access to data about all +[calls][call]. Example: + + +```javascript +var object = { + get test() { + return this.property; + }, + set test(value) { + this.property = value * 2; + } +}; + +var spy = sinon.spy(object, "test", ["get", "set"]); + +object.test = 42; +assert(spy.set.calledOnce); + +assert.equals(object.test, 84); +assert(spy.get.calledOnce); +``` ### Creating spies: `sinon.spy()` Method Signatures @@ -80,6 +106,16 @@ all [calls][call]. The following is a slightly contrived example: object.method.restore(). The returned spy is the function object which replaced the original method. spy === object.method. +
var spy = sinon.spy(object, "property", types);
+
+ Creates a spy for object.property descriptor and replaces the + original accessor methods (`get`, `set`) listed in the types + array with a spy. The spies act exactly like the original accessors in all + cases. The original accessors can be restored by calling + spy.restore(). The returned spy is the object which replaced + the original property descriptor. spy.get === + Object.getOwnPropertyDescriptor(object, 'property').get. +
diff --git a/docs/_releases/v5.0.6/spies.md b/docs/_releases/v5.0.6/spies.md index 39bce5da9..a5ff84f90 100644 --- a/docs/_releases/v5.0.6/spies.md +++ b/docs/_releases/v5.0.6/spies.md @@ -60,6 +60,32 @@ all [calls][call]. The following is a slightly contrived example: } ``` +### Using a spy to wrap property getter and setter + +`sinon.spy(object, "property", ["get", "set"])` creates spies that wrap the +getters and setters for `object.property`. The spies will behave exactly like +the original getters and setters, but you will have access to data about all +[calls][call]. Example: + + +```javascript +var object = { + get test() { + return this.property; + }, + set test(value) { + this.property = value * 2; + } +}; + +var spy = sinon.spy(object, "test", ["get", "set"]); + +object.test = 42; +assert(spy.set.calledOnce); + +assert.equals(object.test, 84); +assert(spy.get.calledOnce); +``` ### Creating spies: `sinon.spy()` Method Signatures @@ -80,6 +106,16 @@ all [calls][call]. The following is a slightly contrived example: object.method.restore(). The returned spy is the function object which replaced the original method. spy === object.method. +
var spy = sinon.spy(object, "property", types);
+
+ Creates a spy for object.property descriptor and replaces the + original accessor methods (`get`, `set`) listed in the types + array with a spy. The spies act exactly like the original accessors in all + cases. The original accessors can be restored by calling + spy.restore(). The returned spy is the object which replaced + the original property descriptor. spy.get === + Object.getOwnPropertyDescriptor(object, 'property').get. +
diff --git a/docs/_releases/v5.0.7/spies.md b/docs/_releases/v5.0.7/spies.md index 39bce5da9..a5ff84f90 100644 --- a/docs/_releases/v5.0.7/spies.md +++ b/docs/_releases/v5.0.7/spies.md @@ -60,6 +60,32 @@ all [calls][call]. The following is a slightly contrived example: } ``` +### Using a spy to wrap property getter and setter + +`sinon.spy(object, "property", ["get", "set"])` creates spies that wrap the +getters and setters for `object.property`. The spies will behave exactly like +the original getters and setters, but you will have access to data about all +[calls][call]. Example: + + +```javascript +var object = { + get test() { + return this.property; + }, + set test(value) { + this.property = value * 2; + } +}; + +var spy = sinon.spy(object, "test", ["get", "set"]); + +object.test = 42; +assert(spy.set.calledOnce); + +assert.equals(object.test, 84); +assert(spy.get.calledOnce); +``` ### Creating spies: `sinon.spy()` Method Signatures @@ -80,6 +106,16 @@ all [calls][call]. The following is a slightly contrived example: object.method.restore(). The returned spy is the function object which replaced the original method. spy === object.method. +
var spy = sinon.spy(object, "property", types);
+
+ Creates a spy for object.property descriptor and replaces the + original accessor methods (`get`, `set`) listed in the types + array with a spy. The spies act exactly like the original accessors in all + cases. The original accessors can be restored by calling + spy.restore(). The returned spy is the object which replaced + the original property descriptor. spy.get === + Object.getOwnPropertyDescriptor(object, 'property').get. +
diff --git a/docs/_releases/v5.0.8/spies.md b/docs/_releases/v5.0.8/spies.md index 39bce5da9..a5ff84f90 100644 --- a/docs/_releases/v5.0.8/spies.md +++ b/docs/_releases/v5.0.8/spies.md @@ -60,6 +60,32 @@ all [calls][call]. The following is a slightly contrived example: } ``` +### Using a spy to wrap property getter and setter + +`sinon.spy(object, "property", ["get", "set"])` creates spies that wrap the +getters and setters for `object.property`. The spies will behave exactly like +the original getters and setters, but you will have access to data about all +[calls][call]. Example: + + +```javascript +var object = { + get test() { + return this.property; + }, + set test(value) { + this.property = value * 2; + } +}; + +var spy = sinon.spy(object, "test", ["get", "set"]); + +object.test = 42; +assert(spy.set.calledOnce); + +assert.equals(object.test, 84); +assert(spy.get.calledOnce); +``` ### Creating spies: `sinon.spy()` Method Signatures @@ -80,6 +106,16 @@ all [calls][call]. The following is a slightly contrived example: object.method.restore(). The returned spy is the function object which replaced the original method. spy === object.method. +
var spy = sinon.spy(object, "property", types);
+
+ Creates a spy for object.property descriptor and replaces the + original accessor methods (`get`, `set`) listed in the types + array with a spy. The spies act exactly like the original accessors in all + cases. The original accessors can be restored by calling + spy.restore(). The returned spy is the object which replaced + the original property descriptor. spy.get === + Object.getOwnPropertyDescriptor(object, 'property').get. +
diff --git a/docs/_releases/v5.0.9/spies.md b/docs/_releases/v5.0.9/spies.md index 39bce5da9..a5ff84f90 100644 --- a/docs/_releases/v5.0.9/spies.md +++ b/docs/_releases/v5.0.9/spies.md @@ -60,6 +60,32 @@ all [calls][call]. The following is a slightly contrived example: } ``` +### Using a spy to wrap property getter and setter + +`sinon.spy(object, "property", ["get", "set"])` creates spies that wrap the +getters and setters for `object.property`. The spies will behave exactly like +the original getters and setters, but you will have access to data about all +[calls][call]. Example: + + +```javascript +var object = { + get test() { + return this.property; + }, + set test(value) { + this.property = value * 2; + } +}; + +var spy = sinon.spy(object, "test", ["get", "set"]); + +object.test = 42; +assert(spy.set.calledOnce); + +assert.equals(object.test, 84); +assert(spy.get.calledOnce); +``` ### Creating spies: `sinon.spy()` Method Signatures @@ -80,6 +106,16 @@ all [calls][call]. The following is a slightly contrived example: object.method.restore(). The returned spy is the function object which replaced the original method. spy === object.method. +
var spy = sinon.spy(object, "property", types);
+
+ Creates a spy for object.property descriptor and replaces the + original accessor methods (`get`, `set`) listed in the types + array with a spy. The spies act exactly like the original accessors in all + cases. The original accessors can be restored by calling + spy.restore(). The returned spy is the object which replaced + the original property descriptor. spy.get === + Object.getOwnPropertyDescriptor(object, 'property').get. +
diff --git a/docs/_releases/v5.1.0/spies.md b/docs/_releases/v5.1.0/spies.md index 39bce5da9..a5ff84f90 100644 --- a/docs/_releases/v5.1.0/spies.md +++ b/docs/_releases/v5.1.0/spies.md @@ -60,6 +60,32 @@ all [calls][call]. The following is a slightly contrived example: } ``` +### Using a spy to wrap property getter and setter + +`sinon.spy(object, "property", ["get", "set"])` creates spies that wrap the +getters and setters for `object.property`. The spies will behave exactly like +the original getters and setters, but you will have access to data about all +[calls][call]. Example: + + +```javascript +var object = { + get test() { + return this.property; + }, + set test(value) { + this.property = value * 2; + } +}; + +var spy = sinon.spy(object, "test", ["get", "set"]); + +object.test = 42; +assert(spy.set.calledOnce); + +assert.equals(object.test, 84); +assert(spy.get.calledOnce); +``` ### Creating spies: `sinon.spy()` Method Signatures @@ -80,6 +106,16 @@ all [calls][call]. The following is a slightly contrived example: object.method.restore(). The returned spy is the function object which replaced the original method. spy === object.method. +
var spy = sinon.spy(object, "property", types);
+
+ Creates a spy for object.property descriptor and replaces the + original accessor methods (`get`, `set`) listed in the types + array with a spy. The spies act exactly like the original accessors in all + cases. The original accessors can be restored by calling + spy.restore(). The returned spy is the object which replaced + the original property descriptor. spy.get === + Object.getOwnPropertyDescriptor(object, 'property').get. +
diff --git a/docs/_releases/v6.0.0/spies.md b/docs/_releases/v6.0.0/spies.md index 39bce5da9..a5ff84f90 100644 --- a/docs/_releases/v6.0.0/spies.md +++ b/docs/_releases/v6.0.0/spies.md @@ -60,6 +60,32 @@ all [calls][call]. The following is a slightly contrived example: } ``` +### Using a spy to wrap property getter and setter + +`sinon.spy(object, "property", ["get", "set"])` creates spies that wrap the +getters and setters for `object.property`. The spies will behave exactly like +the original getters and setters, but you will have access to data about all +[calls][call]. Example: + + +```javascript +var object = { + get test() { + return this.property; + }, + set test(value) { + this.property = value * 2; + } +}; + +var spy = sinon.spy(object, "test", ["get", "set"]); + +object.test = 42; +assert(spy.set.calledOnce); + +assert.equals(object.test, 84); +assert(spy.get.calledOnce); +``` ### Creating spies: `sinon.spy()` Method Signatures @@ -80,6 +106,16 @@ all [calls][call]. The following is a slightly contrived example: object.method.restore(). The returned spy is the function object which replaced the original method. spy === object.method. +
var spy = sinon.spy(object, "property", types);
+
+ Creates a spy for object.property descriptor and replaces the + original accessor methods (`get`, `set`) listed in the types + array with a spy. The spies act exactly like the original accessors in all + cases. The original accessors can be restored by calling + spy.restore(). The returned spy is the object which replaced + the original property descriptor. spy.get === + Object.getOwnPropertyDescriptor(object, 'property').get. +
diff --git a/docs/_releases/v6.0.1/spies.md b/docs/_releases/v6.0.1/spies.md index 39bce5da9..a5ff84f90 100644 --- a/docs/_releases/v6.0.1/spies.md +++ b/docs/_releases/v6.0.1/spies.md @@ -60,6 +60,32 @@ all [calls][call]. The following is a slightly contrived example: } ``` +### Using a spy to wrap property getter and setter + +`sinon.spy(object, "property", ["get", "set"])` creates spies that wrap the +getters and setters for `object.property`. The spies will behave exactly like +the original getters and setters, but you will have access to data about all +[calls][call]. Example: + + +```javascript +var object = { + get test() { + return this.property; + }, + set test(value) { + this.property = value * 2; + } +}; + +var spy = sinon.spy(object, "test", ["get", "set"]); + +object.test = 42; +assert(spy.set.calledOnce); + +assert.equals(object.test, 84); +assert(spy.get.calledOnce); +``` ### Creating spies: `sinon.spy()` Method Signatures @@ -80,6 +106,16 @@ all [calls][call]. The following is a slightly contrived example: object.method.restore(). The returned spy is the function object which replaced the original method. spy === object.method. +
var spy = sinon.spy(object, "property", types);
+
+ Creates a spy for object.property descriptor and replaces the + original accessor methods (`get`, `set`) listed in the types + array with a spy. The spies act exactly like the original accessors in all + cases. The original accessors can be restored by calling + spy.restore(). The returned spy is the object which replaced + the original property descriptor. spy.get === + Object.getOwnPropertyDescriptor(object, 'property').get. +
diff --git a/docs/_releases/v6.1.0/spies.md b/docs/_releases/v6.1.0/spies.md index 39bce5da9..a5ff84f90 100644 --- a/docs/_releases/v6.1.0/spies.md +++ b/docs/_releases/v6.1.0/spies.md @@ -60,6 +60,32 @@ all [calls][call]. The following is a slightly contrived example: } ``` +### Using a spy to wrap property getter and setter + +`sinon.spy(object, "property", ["get", "set"])` creates spies that wrap the +getters and setters for `object.property`. The spies will behave exactly like +the original getters and setters, but you will have access to data about all +[calls][call]. Example: + + +```javascript +var object = { + get test() { + return this.property; + }, + set test(value) { + this.property = value * 2; + } +}; + +var spy = sinon.spy(object, "test", ["get", "set"]); + +object.test = 42; +assert(spy.set.calledOnce); + +assert.equals(object.test, 84); +assert(spy.get.calledOnce); +``` ### Creating spies: `sinon.spy()` Method Signatures @@ -80,6 +106,16 @@ all [calls][call]. The following is a slightly contrived example: object.method.restore(). The returned spy is the function object which replaced the original method. spy === object.method. +
var spy = sinon.spy(object, "property", types);
+
+ Creates a spy for object.property descriptor and replaces the + original accessor methods (`get`, `set`) listed in the types + array with a spy. The spies act exactly like the original accessors in all + cases. The original accessors can be restored by calling + spy.restore(). The returned spy is the object which replaced + the original property descriptor. spy.get === + Object.getOwnPropertyDescriptor(object, 'property').get. +
diff --git a/docs/_releases/v6.1.1/spies.md b/docs/_releases/v6.1.1/spies.md index 39bce5da9..a5ff84f90 100644 --- a/docs/_releases/v6.1.1/spies.md +++ b/docs/_releases/v6.1.1/spies.md @@ -60,6 +60,32 @@ all [calls][call]. The following is a slightly contrived example: } ``` +### Using a spy to wrap property getter and setter + +`sinon.spy(object, "property", ["get", "set"])` creates spies that wrap the +getters and setters for `object.property`. The spies will behave exactly like +the original getters and setters, but you will have access to data about all +[calls][call]. Example: + + +```javascript +var object = { + get test() { + return this.property; + }, + set test(value) { + this.property = value * 2; + } +}; + +var spy = sinon.spy(object, "test", ["get", "set"]); + +object.test = 42; +assert(spy.set.calledOnce); + +assert.equals(object.test, 84); +assert(spy.get.calledOnce); +``` ### Creating spies: `sinon.spy()` Method Signatures @@ -80,6 +106,16 @@ all [calls][call]. The following is a slightly contrived example: object.method.restore(). The returned spy is the function object which replaced the original method. spy === object.method. +
var spy = sinon.spy(object, "property", types);
+
+ Creates a spy for object.property descriptor and replaces the + original accessor methods (`get`, `set`) listed in the types + array with a spy. The spies act exactly like the original accessors in all + cases. The original accessors can be restored by calling + spy.restore(). The returned spy is the object which replaced + the original property descriptor. spy.get === + Object.getOwnPropertyDescriptor(object, 'property').get. +
diff --git a/docs/_releases/v6.1.2/spies.md b/docs/_releases/v6.1.2/spies.md index 39bce5da9..a5ff84f90 100644 --- a/docs/_releases/v6.1.2/spies.md +++ b/docs/_releases/v6.1.2/spies.md @@ -60,6 +60,32 @@ all [calls][call]. The following is a slightly contrived example: } ``` +### Using a spy to wrap property getter and setter + +`sinon.spy(object, "property", ["get", "set"])` creates spies that wrap the +getters and setters for `object.property`. The spies will behave exactly like +the original getters and setters, but you will have access to data about all +[calls][call]. Example: + + +```javascript +var object = { + get test() { + return this.property; + }, + set test(value) { + this.property = value * 2; + } +}; + +var spy = sinon.spy(object, "test", ["get", "set"]); + +object.test = 42; +assert(spy.set.calledOnce); + +assert.equals(object.test, 84); +assert(spy.get.calledOnce); +``` ### Creating spies: `sinon.spy()` Method Signatures @@ -80,6 +106,16 @@ all [calls][call]. The following is a slightly contrived example: object.method.restore(). The returned spy is the function object which replaced the original method. spy === object.method. +
var spy = sinon.spy(object, "property", types);
+
+ Creates a spy for object.property descriptor and replaces the + original accessor methods (`get`, `set`) listed in the types + array with a spy. The spies act exactly like the original accessors in all + cases. The original accessors can be restored by calling + spy.restore(). The returned spy is the object which replaced + the original property descriptor. spy.get === + Object.getOwnPropertyDescriptor(object, 'property').get. +
diff --git a/docs/_releases/v6.1.3/spies.md b/docs/_releases/v6.1.3/spies.md index 39bce5da9..a5ff84f90 100644 --- a/docs/_releases/v6.1.3/spies.md +++ b/docs/_releases/v6.1.3/spies.md @@ -60,6 +60,32 @@ all [calls][call]. The following is a slightly contrived example: } ``` +### Using a spy to wrap property getter and setter + +`sinon.spy(object, "property", ["get", "set"])` creates spies that wrap the +getters and setters for `object.property`. The spies will behave exactly like +the original getters and setters, but you will have access to data about all +[calls][call]. Example: + + +```javascript +var object = { + get test() { + return this.property; + }, + set test(value) { + this.property = value * 2; + } +}; + +var spy = sinon.spy(object, "test", ["get", "set"]); + +object.test = 42; +assert(spy.set.calledOnce); + +assert.equals(object.test, 84); +assert(spy.get.calledOnce); +``` ### Creating spies: `sinon.spy()` Method Signatures @@ -80,6 +106,16 @@ all [calls][call]. The following is a slightly contrived example: object.method.restore(). The returned spy is the function object which replaced the original method. spy === object.method. +
var spy = sinon.spy(object, "property", types);
+
+ Creates a spy for object.property descriptor and replaces the + original accessor methods (`get`, `set`) listed in the types + array with a spy. The spies act exactly like the original accessors in all + cases. The original accessors can be restored by calling + spy.restore(). The returned spy is the object which replaced + the original property descriptor. spy.get === + Object.getOwnPropertyDescriptor(object, 'property').get. +
diff --git a/docs/_releases/v6.1.4/spies.md b/docs/_releases/v6.1.4/spies.md index 906837158..4df4743c0 100644 --- a/docs/_releases/v6.1.4/spies.md +++ b/docs/_releases/v6.1.4/spies.md @@ -60,6 +60,32 @@ all [calls][call]. The following is a slightly contrived example: } ``` +### Using a spy to wrap property getter and setter + +`sinon.spy(object, "property", ["get", "set"])` creates spies that wrap the +getters and setters for `object.property`. The spies will behave exactly like +the original getters and setters, but you will have access to data about all +[calls][call]. Example: + + +```javascript +var object = { + get test() { + return this.property; + }, + set test(value) { + this.property = value * 2; + } +}; + +var spy = sinon.spy(object, "test", ["get", "set"]); + +object.test = 42; +assert(spy.set.calledOnce); + +assert.equals(object.test, 84); +assert(spy.get.calledOnce); +``` ### Creating spies: `sinon.spy()` Method Signatures @@ -80,6 +106,16 @@ all [calls][call]. The following is a slightly contrived example: object.method.restore(). The returned spy is the function object which replaced the original method. spy === object.method. +
var spy = sinon.spy(object, "property", types);
+
+ Creates a spy for object.property descriptor and replaces the + original accessor methods (`get`, `set`) listed in the types + array with a spy. The spies act exactly like the original accessors in all + cases. The original accessors can be restored by calling + spy.restore(). The returned spy is the object which replaced + the original property descriptor. spy.get === + Object.getOwnPropertyDescriptor(object, 'property').get. +
diff --git a/docs/_releases/v6.1.5/spies.md b/docs/_releases/v6.1.5/spies.md index 906837158..4df4743c0 100644 --- a/docs/_releases/v6.1.5/spies.md +++ b/docs/_releases/v6.1.5/spies.md @@ -60,6 +60,32 @@ all [calls][call]. The following is a slightly contrived example: } ``` +### Using a spy to wrap property getter and setter + +`sinon.spy(object, "property", ["get", "set"])` creates spies that wrap the +getters and setters for `object.property`. The spies will behave exactly like +the original getters and setters, but you will have access to data about all +[calls][call]. Example: + + +```javascript +var object = { + get test() { + return this.property; + }, + set test(value) { + this.property = value * 2; + } +}; + +var spy = sinon.spy(object, "test", ["get", "set"]); + +object.test = 42; +assert(spy.set.calledOnce); + +assert.equals(object.test, 84); +assert(spy.get.calledOnce); +``` ### Creating spies: `sinon.spy()` Method Signatures @@ -80,6 +106,16 @@ all [calls][call]. The following is a slightly contrived example: object.method.restore(). The returned spy is the function object which replaced the original method. spy === object.method. +
var spy = sinon.spy(object, "property", types);
+
+ Creates a spy for object.property descriptor and replaces the + original accessor methods (`get`, `set`) listed in the types + array with a spy. The spies act exactly like the original accessors in all + cases. The original accessors can be restored by calling + spy.restore(). The returned spy is the object which replaced + the original property descriptor. spy.get === + Object.getOwnPropertyDescriptor(object, 'property').get. +
diff --git a/docs/_releases/v6.1.6/spies.md b/docs/_releases/v6.1.6/spies.md index 906837158..4df4743c0 100644 --- a/docs/_releases/v6.1.6/spies.md +++ b/docs/_releases/v6.1.6/spies.md @@ -60,6 +60,32 @@ all [calls][call]. The following is a slightly contrived example: } ``` +### Using a spy to wrap property getter and setter + +`sinon.spy(object, "property", ["get", "set"])` creates spies that wrap the +getters and setters for `object.property`. The spies will behave exactly like +the original getters and setters, but you will have access to data about all +[calls][call]. Example: + + +```javascript +var object = { + get test() { + return this.property; + }, + set test(value) { + this.property = value * 2; + } +}; + +var spy = sinon.spy(object, "test", ["get", "set"]); + +object.test = 42; +assert(spy.set.calledOnce); + +assert.equals(object.test, 84); +assert(spy.get.calledOnce); +``` ### Creating spies: `sinon.spy()` Method Signatures @@ -80,6 +106,16 @@ all [calls][call]. The following is a slightly contrived example: object.method.restore(). The returned spy is the function object which replaced the original method. spy === object.method. +
var spy = sinon.spy(object, "property", types);
+
+ Creates a spy for object.property descriptor and replaces the + original accessor methods (`get`, `set`) listed in the types + array with a spy. The spies act exactly like the original accessors in all + cases. The original accessors can be restored by calling + spy.restore(). The returned spy is the object which replaced + the original property descriptor. spy.get === + Object.getOwnPropertyDescriptor(object, 'property').get. +
diff --git a/docs/_releases/v6.2.0/spies.md b/docs/_releases/v6.2.0/spies.md index 906837158..4df4743c0 100644 --- a/docs/_releases/v6.2.0/spies.md +++ b/docs/_releases/v6.2.0/spies.md @@ -60,6 +60,32 @@ all [calls][call]. The following is a slightly contrived example: } ``` +### Using a spy to wrap property getter and setter + +`sinon.spy(object, "property", ["get", "set"])` creates spies that wrap the +getters and setters for `object.property`. The spies will behave exactly like +the original getters and setters, but you will have access to data about all +[calls][call]. Example: + + +```javascript +var object = { + get test() { + return this.property; + }, + set test(value) { + this.property = value * 2; + } +}; + +var spy = sinon.spy(object, "test", ["get", "set"]); + +object.test = 42; +assert(spy.set.calledOnce); + +assert.equals(object.test, 84); +assert(spy.get.calledOnce); +``` ### Creating spies: `sinon.spy()` Method Signatures @@ -80,6 +106,16 @@ all [calls][call]. The following is a slightly contrived example: object.method.restore(). The returned spy is the function object which replaced the original method. spy === object.method. +
var spy = sinon.spy(object, "property", types);
+
+ Creates a spy for object.property descriptor and replaces the + original accessor methods (`get`, `set`) listed in the types + array with a spy. The spies act exactly like the original accessors in all + cases. The original accessors can be restored by calling + spy.restore(). The returned spy is the object which replaced + the original property descriptor. spy.get === + Object.getOwnPropertyDescriptor(object, 'property').get. +
diff --git a/docs/_releases/v6.3.0/spies.md b/docs/_releases/v6.3.0/spies.md index 906837158..4df4743c0 100644 --- a/docs/_releases/v6.3.0/spies.md +++ b/docs/_releases/v6.3.0/spies.md @@ -60,6 +60,32 @@ all [calls][call]. The following is a slightly contrived example: } ``` +### Using a spy to wrap property getter and setter + +`sinon.spy(object, "property", ["get", "set"])` creates spies that wrap the +getters and setters for `object.property`. The spies will behave exactly like +the original getters and setters, but you will have access to data about all +[calls][call]. Example: + + +```javascript +var object = { + get test() { + return this.property; + }, + set test(value) { + this.property = value * 2; + } +}; + +var spy = sinon.spy(object, "test", ["get", "set"]); + +object.test = 42; +assert(spy.set.calledOnce); + +assert.equals(object.test, 84); +assert(spy.get.calledOnce); +``` ### Creating spies: `sinon.spy()` Method Signatures @@ -80,6 +106,16 @@ all [calls][call]. The following is a slightly contrived example: object.method.restore(). The returned spy is the function object which replaced the original method. spy === object.method. +
var spy = sinon.spy(object, "property", types);
+
+ Creates a spy for object.property descriptor and replaces the + original accessor methods (`get`, `set`) listed in the types + array with a spy. The spies act exactly like the original accessors in all + cases. The original accessors can be restored by calling + spy.restore(). The returned spy is the object which replaced + the original property descriptor. spy.get === + Object.getOwnPropertyDescriptor(object, 'property').get. +
diff --git a/docs/_releases/v6.3.1/spies.md b/docs/_releases/v6.3.1/spies.md index 906837158..4df4743c0 100644 --- a/docs/_releases/v6.3.1/spies.md +++ b/docs/_releases/v6.3.1/spies.md @@ -60,6 +60,32 @@ all [calls][call]. The following is a slightly contrived example: } ``` +### Using a spy to wrap property getter and setter + +`sinon.spy(object, "property", ["get", "set"])` creates spies that wrap the +getters and setters for `object.property`. The spies will behave exactly like +the original getters and setters, but you will have access to data about all +[calls][call]. Example: + + +```javascript +var object = { + get test() { + return this.property; + }, + set test(value) { + this.property = value * 2; + } +}; + +var spy = sinon.spy(object, "test", ["get", "set"]); + +object.test = 42; +assert(spy.set.calledOnce); + +assert.equals(object.test, 84); +assert(spy.get.calledOnce); +``` ### Creating spies: `sinon.spy()` Method Signatures @@ -80,6 +106,16 @@ all [calls][call]. The following is a slightly contrived example: object.method.restore(). The returned spy is the function object which replaced the original method. spy === object.method. +
var spy = sinon.spy(object, "property", types);
+
+ Creates a spy for object.property descriptor and replaces the + original accessor methods (`get`, `set`) listed in the types + array with a spy. The spies act exactly like the original accessors in all + cases. The original accessors can be restored by calling + spy.restore(). The returned spy is the object which replaced + the original property descriptor. spy.get === + Object.getOwnPropertyDescriptor(object, 'property').get. +
diff --git a/docs/_releases/v6.3.2/spies.md b/docs/_releases/v6.3.2/spies.md index 906837158..4df4743c0 100644 --- a/docs/_releases/v6.3.2/spies.md +++ b/docs/_releases/v6.3.2/spies.md @@ -60,6 +60,32 @@ all [calls][call]. The following is a slightly contrived example: } ``` +### Using a spy to wrap property getter and setter + +`sinon.spy(object, "property", ["get", "set"])` creates spies that wrap the +getters and setters for `object.property`. The spies will behave exactly like +the original getters and setters, but you will have access to data about all +[calls][call]. Example: + + +```javascript +var object = { + get test() { + return this.property; + }, + set test(value) { + this.property = value * 2; + } +}; + +var spy = sinon.spy(object, "test", ["get", "set"]); + +object.test = 42; +assert(spy.set.calledOnce); + +assert.equals(object.test, 84); +assert(spy.get.calledOnce); +``` ### Creating spies: `sinon.spy()` Method Signatures @@ -80,6 +106,16 @@ all [calls][call]. The following is a slightly contrived example: object.method.restore(). The returned spy is the function object which replaced the original method. spy === object.method. +
var spy = sinon.spy(object, "property", types);
+
+ Creates a spy for object.property descriptor and replaces the + original accessor methods (`get`, `set`) listed in the types + array with a spy. The spies act exactly like the original accessors in all + cases. The original accessors can be restored by calling + spy.restore(). The returned spy is the object which replaced + the original property descriptor. spy.get === + Object.getOwnPropertyDescriptor(object, 'property').get. +
diff --git a/docs/_releases/v6.3.3/spies.md b/docs/_releases/v6.3.3/spies.md index 906837158..4df4743c0 100644 --- a/docs/_releases/v6.3.3/spies.md +++ b/docs/_releases/v6.3.3/spies.md @@ -60,6 +60,32 @@ all [calls][call]. The following is a slightly contrived example: } ``` +### Using a spy to wrap property getter and setter + +`sinon.spy(object, "property", ["get", "set"])` creates spies that wrap the +getters and setters for `object.property`. The spies will behave exactly like +the original getters and setters, but you will have access to data about all +[calls][call]. Example: + + +```javascript +var object = { + get test() { + return this.property; + }, + set test(value) { + this.property = value * 2; + } +}; + +var spy = sinon.spy(object, "test", ["get", "set"]); + +object.test = 42; +assert(spy.set.calledOnce); + +assert.equals(object.test, 84); +assert(spy.get.calledOnce); +``` ### Creating spies: `sinon.spy()` Method Signatures @@ -80,6 +106,16 @@ all [calls][call]. The following is a slightly contrived example: object.method.restore(). The returned spy is the function object which replaced the original method. spy === object.method. +
var spy = sinon.spy(object, "property", types);
+
+ Creates a spy for object.property descriptor and replaces the + original accessor methods (`get`, `set`) listed in the types + array with a spy. The spies act exactly like the original accessors in all + cases. The original accessors can be restored by calling + spy.restore(). The returned spy is the object which replaced + the original property descriptor. spy.get === + Object.getOwnPropertyDescriptor(object, 'property').get. +
diff --git a/docs/_releases/v6.3.4/spies.md b/docs/_releases/v6.3.4/spies.md index 906837158..4df4743c0 100644 --- a/docs/_releases/v6.3.4/spies.md +++ b/docs/_releases/v6.3.4/spies.md @@ -60,6 +60,32 @@ all [calls][call]. The following is a slightly contrived example: } ``` +### Using a spy to wrap property getter and setter + +`sinon.spy(object, "property", ["get", "set"])` creates spies that wrap the +getters and setters for `object.property`. The spies will behave exactly like +the original getters and setters, but you will have access to data about all +[calls][call]. Example: + + +```javascript +var object = { + get test() { + return this.property; + }, + set test(value) { + this.property = value * 2; + } +}; + +var spy = sinon.spy(object, "test", ["get", "set"]); + +object.test = 42; +assert(spy.set.calledOnce); + +assert.equals(object.test, 84); +assert(spy.get.calledOnce); +``` ### Creating spies: `sinon.spy()` Method Signatures @@ -80,6 +106,16 @@ all [calls][call]. The following is a slightly contrived example: object.method.restore(). The returned spy is the function object which replaced the original method. spy === object.method. +
var spy = sinon.spy(object, "property", types);
+
+ Creates a spy for object.property descriptor and replaces the + original accessor methods (`get`, `set`) listed in the types + array with a spy. The spies act exactly like the original accessors in all + cases. The original accessors can be restored by calling + spy.restore(). The returned spy is the object which replaced + the original property descriptor. spy.get === + Object.getOwnPropertyDescriptor(object, 'property').get. +
diff --git a/docs/_releases/v6.3.5/spies.md b/docs/_releases/v6.3.5/spies.md index 906837158..4df4743c0 100644 --- a/docs/_releases/v6.3.5/spies.md +++ b/docs/_releases/v6.3.5/spies.md @@ -60,6 +60,32 @@ all [calls][call]. The following is a slightly contrived example: } ``` +### Using a spy to wrap property getter and setter + +`sinon.spy(object, "property", ["get", "set"])` creates spies that wrap the +getters and setters for `object.property`. The spies will behave exactly like +the original getters and setters, but you will have access to data about all +[calls][call]. Example: + + +```javascript +var object = { + get test() { + return this.property; + }, + set test(value) { + this.property = value * 2; + } +}; + +var spy = sinon.spy(object, "test", ["get", "set"]); + +object.test = 42; +assert(spy.set.calledOnce); + +assert.equals(object.test, 84); +assert(spy.get.calledOnce); +``` ### Creating spies: `sinon.spy()` Method Signatures @@ -80,6 +106,16 @@ all [calls][call]. The following is a slightly contrived example: object.method.restore(). The returned spy is the function object which replaced the original method. spy === object.method. +
var spy = sinon.spy(object, "property", types);
+
+ Creates a spy for object.property descriptor and replaces the + original accessor methods (`get`, `set`) listed in the types + array with a spy. The spies act exactly like the original accessors in all + cases. The original accessors can be restored by calling + spy.restore(). The returned spy is the object which replaced + the original property descriptor. spy.get === + Object.getOwnPropertyDescriptor(object, 'property').get. +
diff --git a/docs/_releases/v7.0.0/spies.md b/docs/_releases/v7.0.0/spies.md index 906837158..4df4743c0 100644 --- a/docs/_releases/v7.0.0/spies.md +++ b/docs/_releases/v7.0.0/spies.md @@ -60,6 +60,32 @@ all [calls][call]. The following is a slightly contrived example: } ``` +### Using a spy to wrap property getter and setter + +`sinon.spy(object, "property", ["get", "set"])` creates spies that wrap the +getters and setters for `object.property`. The spies will behave exactly like +the original getters and setters, but you will have access to data about all +[calls][call]. Example: + + +```javascript +var object = { + get test() { + return this.property; + }, + set test(value) { + this.property = value * 2; + } +}; + +var spy = sinon.spy(object, "test", ["get", "set"]); + +object.test = 42; +assert(spy.set.calledOnce); + +assert.equals(object.test, 84); +assert(spy.get.calledOnce); +``` ### Creating spies: `sinon.spy()` Method Signatures @@ -80,6 +106,16 @@ all [calls][call]. The following is a slightly contrived example: object.method.restore(). The returned spy is the function object which replaced the original method. spy === object.method. +
var spy = sinon.spy(object, "property", types);
+
+ Creates a spy for object.property descriptor and replaces the + original accessor methods (`get`, `set`) listed in the types + array with a spy. The spies act exactly like the original accessors in all + cases. The original accessors can be restored by calling + spy.restore(). The returned spy is the object which replaced + the original property descriptor. spy.get === + Object.getOwnPropertyDescriptor(object, 'property').get. +
diff --git a/docs/_releases/v7.1.0/spies.md b/docs/_releases/v7.1.0/spies.md index 906837158..4df4743c0 100644 --- a/docs/_releases/v7.1.0/spies.md +++ b/docs/_releases/v7.1.0/spies.md @@ -60,6 +60,32 @@ all [calls][call]. The following is a slightly contrived example: } ``` +### Using a spy to wrap property getter and setter + +`sinon.spy(object, "property", ["get", "set"])` creates spies that wrap the +getters and setters for `object.property`. The spies will behave exactly like +the original getters and setters, but you will have access to data about all +[calls][call]. Example: + + +```javascript +var object = { + get test() { + return this.property; + }, + set test(value) { + this.property = value * 2; + } +}; + +var spy = sinon.spy(object, "test", ["get", "set"]); + +object.test = 42; +assert(spy.set.calledOnce); + +assert.equals(object.test, 84); +assert(spy.get.calledOnce); +``` ### Creating spies: `sinon.spy()` Method Signatures @@ -80,6 +106,16 @@ all [calls][call]. The following is a slightly contrived example: object.method.restore(). The returned spy is the function object which replaced the original method. spy === object.method. +
var spy = sinon.spy(object, "property", types);
+
+ Creates a spy for object.property descriptor and replaces the + original accessor methods (`get`, `set`) listed in the types + array with a spy. The spies act exactly like the original accessors in all + cases. The original accessors can be restored by calling + spy.restore(). The returned spy is the object which replaced + the original property descriptor. spy.get === + Object.getOwnPropertyDescriptor(object, 'property').get. +
diff --git a/docs/_releases/v7.1.1/spies.md b/docs/_releases/v7.1.1/spies.md index 906837158..4df4743c0 100644 --- a/docs/_releases/v7.1.1/spies.md +++ b/docs/_releases/v7.1.1/spies.md @@ -60,6 +60,32 @@ all [calls][call]. The following is a slightly contrived example: } ``` +### Using a spy to wrap property getter and setter + +`sinon.spy(object, "property", ["get", "set"])` creates spies that wrap the +getters and setters for `object.property`. The spies will behave exactly like +the original getters and setters, but you will have access to data about all +[calls][call]. Example: + + +```javascript +var object = { + get test() { + return this.property; + }, + set test(value) { + this.property = value * 2; + } +}; + +var spy = sinon.spy(object, "test", ["get", "set"]); + +object.test = 42; +assert(spy.set.calledOnce); + +assert.equals(object.test, 84); +assert(spy.get.calledOnce); +``` ### Creating spies: `sinon.spy()` Method Signatures @@ -80,6 +106,16 @@ all [calls][call]. The following is a slightly contrived example: object.method.restore(). The returned spy is the function object which replaced the original method. spy === object.method. +
var spy = sinon.spy(object, "property", types);
+
+ Creates a spy for object.property descriptor and replaces the + original accessor methods (`get`, `set`) listed in the types + array with a spy. The spies act exactly like the original accessors in all + cases. The original accessors can be restored by calling + spy.restore(). The returned spy is the object which replaced + the original property descriptor. spy.get === + Object.getOwnPropertyDescriptor(object, 'property').get. +
diff --git a/docs/_releases/v7.2.0/spies.md b/docs/_releases/v7.2.0/spies.md index 906837158..4df4743c0 100644 --- a/docs/_releases/v7.2.0/spies.md +++ b/docs/_releases/v7.2.0/spies.md @@ -60,6 +60,32 @@ all [calls][call]. The following is a slightly contrived example: } ``` +### Using a spy to wrap property getter and setter + +`sinon.spy(object, "property", ["get", "set"])` creates spies that wrap the +getters and setters for `object.property`. The spies will behave exactly like +the original getters and setters, but you will have access to data about all +[calls][call]. Example: + + +```javascript +var object = { + get test() { + return this.property; + }, + set test(value) { + this.property = value * 2; + } +}; + +var spy = sinon.spy(object, "test", ["get", "set"]); + +object.test = 42; +assert(spy.set.calledOnce); + +assert.equals(object.test, 84); +assert(spy.get.calledOnce); +``` ### Creating spies: `sinon.spy()` Method Signatures @@ -80,6 +106,16 @@ all [calls][call]. The following is a slightly contrived example: object.method.restore(). The returned spy is the function object which replaced the original method. spy === object.method. +
var spy = sinon.spy(object, "property", types);
+
+ Creates a spy for object.property descriptor and replaces the + original accessor methods (`get`, `set`) listed in the types + array with a spy. The spies act exactly like the original accessors in all + cases. The original accessors can be restored by calling + spy.restore(). The returned spy is the object which replaced + the original property descriptor. spy.get === + Object.getOwnPropertyDescriptor(object, 'property').get. +
diff --git a/docs/_releases/v7.2.1/spies.md b/docs/_releases/v7.2.1/spies.md index 906837158..4df4743c0 100644 --- a/docs/_releases/v7.2.1/spies.md +++ b/docs/_releases/v7.2.1/spies.md @@ -60,6 +60,32 @@ all [calls][call]. The following is a slightly contrived example: } ``` +### Using a spy to wrap property getter and setter + +`sinon.spy(object, "property", ["get", "set"])` creates spies that wrap the +getters and setters for `object.property`. The spies will behave exactly like +the original getters and setters, but you will have access to data about all +[calls][call]. Example: + + +```javascript +var object = { + get test() { + return this.property; + }, + set test(value) { + this.property = value * 2; + } +}; + +var spy = sinon.spy(object, "test", ["get", "set"]); + +object.test = 42; +assert(spy.set.calledOnce); + +assert.equals(object.test, 84); +assert(spy.get.calledOnce); +``` ### Creating spies: `sinon.spy()` Method Signatures @@ -80,6 +106,16 @@ all [calls][call]. The following is a slightly contrived example: object.method.restore(). The returned spy is the function object which replaced the original method. spy === object.method. +
var spy = sinon.spy(object, "property", types);
+
+ Creates a spy for object.property descriptor and replaces the + original accessor methods (`get`, `set`) listed in the types + array with a spy. The spies act exactly like the original accessors in all + cases. The original accessors can be restored by calling + spy.restore(). The returned spy is the object which replaced + the original property descriptor. spy.get === + Object.getOwnPropertyDescriptor(object, 'property').get. +
diff --git a/docs/_releases/v7.2.2/spies.md b/docs/_releases/v7.2.2/spies.md index 906837158..4df4743c0 100644 --- a/docs/_releases/v7.2.2/spies.md +++ b/docs/_releases/v7.2.2/spies.md @@ -60,6 +60,32 @@ all [calls][call]. The following is a slightly contrived example: } ``` +### Using a spy to wrap property getter and setter + +`sinon.spy(object, "property", ["get", "set"])` creates spies that wrap the +getters and setters for `object.property`. The spies will behave exactly like +the original getters and setters, but you will have access to data about all +[calls][call]. Example: + + +```javascript +var object = { + get test() { + return this.property; + }, + set test(value) { + this.property = value * 2; + } +}; + +var spy = sinon.spy(object, "test", ["get", "set"]); + +object.test = 42; +assert(spy.set.calledOnce); + +assert.equals(object.test, 84); +assert(spy.get.calledOnce); +``` ### Creating spies: `sinon.spy()` Method Signatures @@ -80,6 +106,16 @@ all [calls][call]. The following is a slightly contrived example: object.method.restore(). The returned spy is the function object which replaced the original method. spy === object.method. +
var spy = sinon.spy(object, "property", types);
+
+ Creates a spy for object.property descriptor and replaces the + original accessor methods (`get`, `set`) listed in the types + array with a spy. The spies act exactly like the original accessors in all + cases. The original accessors can be restored by calling + spy.restore(). The returned spy is the object which replaced + the original property descriptor. spy.get === + Object.getOwnPropertyDescriptor(object, 'property').get. +
diff --git a/docs/_releases/v7.2.3/spies.md b/docs/_releases/v7.2.3/spies.md index 906837158..4df4743c0 100644 --- a/docs/_releases/v7.2.3/spies.md +++ b/docs/_releases/v7.2.3/spies.md @@ -60,6 +60,32 @@ all [calls][call]. The following is a slightly contrived example: } ``` +### Using a spy to wrap property getter and setter + +`sinon.spy(object, "property", ["get", "set"])` creates spies that wrap the +getters and setters for `object.property`. The spies will behave exactly like +the original getters and setters, but you will have access to data about all +[calls][call]. Example: + + +```javascript +var object = { + get test() { + return this.property; + }, + set test(value) { + this.property = value * 2; + } +}; + +var spy = sinon.spy(object, "test", ["get", "set"]); + +object.test = 42; +assert(spy.set.calledOnce); + +assert.equals(object.test, 84); +assert(spy.get.calledOnce); +``` ### Creating spies: `sinon.spy()` Method Signatures @@ -80,6 +106,16 @@ all [calls][call]. The following is a slightly contrived example: object.method.restore(). The returned spy is the function object which replaced the original method. spy === object.method. +
var spy = sinon.spy(object, "property", types);
+
+ Creates a spy for object.property descriptor and replaces the + original accessor methods (`get`, `set`) listed in the types + array with a spy. The spies act exactly like the original accessors in all + cases. The original accessors can be restored by calling + spy.restore(). The returned spy is the object which replaced + the original property descriptor. spy.get === + Object.getOwnPropertyDescriptor(object, 'property').get. +