Skip to content

Commit

Permalink
Document spying on accessors (#1976)
Browse files Browse the repository at this point in the history
  • Loading branch information
salomvary authored and mroderick committed Mar 4, 2019
1 parent 0468cd4 commit 3275d18
Show file tree
Hide file tree
Showing 83 changed files with 2,988 additions and 0 deletions.
36 changes: 36 additions & 0 deletions docs/_releases/latest/spies.md
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand All @@ -80,6 +106,16 @@ all [calls][call]. The following is a slightly contrived example:
<code>object.method.restore()</code>. The returned spy is the function
object which replaced the original method. <code>spy === object.method</code>.
</dd>
<dt><code>var spy = sinon.spy(object, "property", types);</code></dt>
<dd>
Creates a spy for <code>object.property</code> descriptor and replaces the
original accessor methods (`get`, `set`) listed in the <code>types</code>
array with a spy. The spies act exactly like the original accessors in all
cases. The original accessors can be restored by calling
<code>spy.restore()</code>. The returned spy is the object which replaced
the original property descriptor. <code>spy.get ===
Object.getOwnPropertyDescriptor(object, 'property').get</code>.
</dd>
</dl>


Expand Down
36 changes: 36 additions & 0 deletions docs/_releases/v1.17.6/spies.md
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand All @@ -80,6 +106,16 @@ all [calls][call]. The following is a slightly contrived example:
<code>object.method.restore()</code>. The returned spy is the function
object which replaced the original method. <code>spy === object.method</code>.
</dd>
<dt><code>var spy = sinon.spy(object, "property", types);</code></dt>
<dd>
Creates a spy for <code>object.property</code> descriptor and replaces the
original accessor methods (`get`, `set`) listed in the <code>types</code>
array with a spy. The spies act exactly like the original accessors in all
cases. The original accessors can be restored by calling
<code>spy.restore()</code>. The returned spy is the object which replaced
the original property descriptor. <code>spy.get ===
Object.getOwnPropertyDescriptor(object, 'property').get</code>.
</dd>
</dl>


Expand Down
36 changes: 36 additions & 0 deletions docs/_releases/v1.17.7/spies.md
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand All @@ -80,6 +106,16 @@ all [calls][call]. The following is a slightly contrived example:
<code>object.method.restore()</code>. The returned spy is the function
object which replaced the original method. <code>spy === object.method</code>.
</dd>
<dt><code>var spy = sinon.spy(object, "property", types);</code></dt>
<dd>
Creates a spy for <code>object.property</code> descriptor and replaces the
original accessor methods (`get`, `set`) listed in the <code>types</code>
array with a spy. The spies act exactly like the original accessors in all
cases. The original accessors can be restored by calling
<code>spy.restore()</code>. The returned spy is the object which replaced
the original property descriptor. <code>spy.get ===
Object.getOwnPropertyDescriptor(object, 'property').get</code>.
</dd>
</dl>


Expand Down
36 changes: 36 additions & 0 deletions docs/_releases/v2.0.0/spies.md
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand All @@ -80,6 +106,16 @@ all [calls][call]. The following is a slightly contrived example:
<code>object.method.restore()</code>. The returned spy is the function
object which replaced the original method. <code>spy === object.method</code>.
</dd>
<dt><code>var spy = sinon.spy(object, "property", types);</code></dt>
<dd>
Creates a spy for <code>object.property</code> descriptor and replaces the
original accessor methods (`get`, `set`) listed in the <code>types</code>
array with a spy. The spies act exactly like the original accessors in all
cases. The original accessors can be restored by calling
<code>spy.restore()</code>. The returned spy is the object which replaced
the original property descriptor. <code>spy.get ===
Object.getOwnPropertyDescriptor(object, 'property').get</code>.
</dd>
</dl>


Expand Down
36 changes: 36 additions & 0 deletions docs/_releases/v2.1.0/spies.md
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand All @@ -80,6 +106,16 @@ all [calls][call]. The following is a slightly contrived example:
<code>object.method.restore()</code>. The returned spy is the function
object which replaced the original method. <code>spy === object.method</code>.
</dd>
<dt><code>var spy = sinon.spy(object, "property", types);</code></dt>
<dd>
Creates a spy for <code>object.property</code> descriptor and replaces the
original accessor methods (`get`, `set`) listed in the <code>types</code>
array with a spy. The spies act exactly like the original accessors in all
cases. The original accessors can be restored by calling
<code>spy.restore()</code>. The returned spy is the object which replaced
the original property descriptor. <code>spy.get ===
Object.getOwnPropertyDescriptor(object, 'property').get</code>.
</dd>
</dl>


Expand Down
36 changes: 36 additions & 0 deletions docs/_releases/v2.2.0/spies.md
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand All @@ -80,6 +106,16 @@ all [calls][call]. The following is a slightly contrived example:
<code>object.method.restore()</code>. The returned spy is the function
object which replaced the original method. <code>spy === object.method</code>.
</dd>
<dt><code>var spy = sinon.spy(object, "property", types);</code></dt>
<dd>
Creates a spy for <code>object.property</code> descriptor and replaces the
original accessor methods (`get`, `set`) listed in the <code>types</code>
array with a spy. The spies act exactly like the original accessors in all
cases. The original accessors can be restored by calling
<code>spy.restore()</code>. The returned spy is the object which replaced
the original property descriptor. <code>spy.get ===
Object.getOwnPropertyDescriptor(object, 'property').get</code>.
</dd>
</dl>


Expand Down
36 changes: 36 additions & 0 deletions docs/_releases/v2.3.0/spies.md
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand All @@ -80,6 +106,16 @@ all [calls][call]. The following is a slightly contrived example:
<code>object.method.restore()</code>. The returned spy is the function
object which replaced the original method. <code>spy === object.method</code>.
</dd>
<dt><code>var spy = sinon.spy(object, "property", types);</code></dt>
<dd>
Creates a spy for <code>object.property</code> descriptor and replaces the
original accessor methods (`get`, `set`) listed in the <code>types</code>
array with a spy. The spies act exactly like the original accessors in all
cases. The original accessors can be restored by calling
<code>spy.restore()</code>. The returned spy is the object which replaced
the original property descriptor. <code>spy.get ===
Object.getOwnPropertyDescriptor(object, 'property').get</code>.
</dd>
</dl>


Expand Down
36 changes: 36 additions & 0 deletions docs/_releases/v2.3.1/spies.md
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand All @@ -80,6 +106,16 @@ all [calls][call]. The following is a slightly contrived example:
<code>object.method.restore()</code>. The returned spy is the function
object which replaced the original method. <code>spy === object.method</code>.
</dd>
<dt><code>var spy = sinon.spy(object, "property", types);</code></dt>
<dd>
Creates a spy for <code>object.property</code> descriptor and replaces the
original accessor methods (`get`, `set`) listed in the <code>types</code>
array with a spy. The spies act exactly like the original accessors in all
cases. The original accessors can be restored by calling
<code>spy.restore()</code>. The returned spy is the object which replaced
the original property descriptor. <code>spy.get ===
Object.getOwnPropertyDescriptor(object, 'property').get</code>.
</dd>
</dl>


Expand Down
Loading

0 comments on commit 3275d18

Please sign in to comment.