Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Document spying on accessors #1976

Merged
merged 2 commits into from
Mar 4, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
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