Skip to content

Commit

Permalink
Add release documentation for v7.4.1
Browse files Browse the repository at this point in the history
  • Loading branch information
fatso83 committed Aug 6, 2019
1 parent 56b00a7 commit dce58d4
Show file tree
Hide file tree
Showing 20 changed files with 3,108 additions and 26 deletions.
2 changes: 1 addition & 1 deletion docs/_releases/latest.md
@@ -1,7 +1,7 @@
---
layout: page
title: API documentation - Sinon.JS
release_id: v7.3.2
release_id: v7.4.1
---

# {{page.title}} - `{{page.release_id}}`
Expand Down
31 changes: 19 additions & 12 deletions docs/_releases/latest/fakes.md
Expand Up @@ -67,26 +67,33 @@ Creates a fake that returns a rejected `Promise` for the passed value.

If an `Error` is passed as the `value` argument, then that will be the value of the promise. If any other value is passed, then that will be used for the `message` property of the `Error` returned by the promise.

#### `sinon.fake.yields(callback[, value1, ..., valueN]);`
#### `sinon.fake.yields([value1, ..., valueN]);`

`fake` expects the last argument to be a callback and will invoke it with the given arguments.
`sinon.fake.yields` takes some values, and returns a function that when being called, expects the last argument to be a callback and invokes that callback with the same previously given values. The returned function is normally used to fake a service function that takes a callback as the last argument.

```js
var fake = sinon.fake.yields('hello world');
In code example below, the '[readFile](https://nodejs.org/api/fs.html#fs_fs_readfile_path_options_callback)' function of the 'fs' module is replaced with a fake function created by `sinon.fake.yields`. When the fake function is called, it always calls the last argument it received, which is expected to be a callback, with the values that the `yields` function previously took.

fake(console.log);
// hello world
```js
var fake = sinon.fake.yields(null, 'file content');
sinon.replace(fs, 'readFile', fake);
fs.readFile('somefile',(err,data)=>{console.log(data);});
console.log('end of this event loop');
// file content
// end of this event loop
```
#### `sinon.fake.yieldsAsync([value1, ..., valueN]);`

#### `sinon.fake.yieldsAsync(callback[, value1, ..., valueN]);`
Similar to `yields`, `yieldsAsync` also returns a function that when invoked, the function expects the last argument to be a callback and invokes that callback with the same previously given values. However, the returned function invokes that callback asynchronously rather than immediately, i.e. in the next event loop.

`fake` expects the last argument to be a callback and will invoke it asynchronously with the given arguments.
Compare the output of the code example below with the output of the code example above for `yields` to see the difference.

```js
var fake = sinon.fake.yieldsAsync('hello world');

fake(console.log);
// hello world
var fakeAsync = sinon.fake.yieldsAsync(null, 'file content');
sinon.replace(fs, 'readFile', fakeAsync);
fs.readFile('somefile',(err,data)=>{console.log(data);});
console.log('end of this event loop');
// end of this event loop
// file content
```

#### `sinon.fake(func);`
Expand Down
2 changes: 1 addition & 1 deletion docs/_releases/latest/sandbox.md
Expand Up @@ -139,7 +139,7 @@ sinon.config = {

#### `sandbox.assert();`

A convenience reference for [`sinon.assert`](../assertions)
A convenience reference for [`sinon.assert`](./assertions)

*Since `sinon@2.0.0`*

Expand Down
9 changes: 4 additions & 5 deletions docs/_releases/latest/spies.md
Expand Up @@ -241,7 +241,7 @@ occurred between `anotherSpy` and `spy`.

#### `spy.calledOn(obj);`

Returns `true` if the spy was called at least once with `obj` as `this`. `calledOn` also accepts a matcher `spyCall.calledOn(sinon.match(fn))` (see [matchers][matchers]).
Returns `true` if the spy was called at least once with `obj` as `this`. `calledOn` also accepts a matcher `spyCall.calledOn(sinon.match(fn))` (see [matchers](matchers)).


#### `spy.alwaysCalledOn(obj);`
Expand All @@ -257,7 +257,7 @@ Can be used for partial matching, Sinon only checks the provided arguments again

#### `spy.calledOnceWith(arg1, arg2, ...);`

Returns `true` if spy was called at exactly once with the provided arguments.
Returns `true` if spy was called exactly once in total and that one call was using the provided arguments.


#### `spy.alwaysCalledWith(arg1, arg2, ...);`
Expand All @@ -271,7 +271,7 @@ Returns `true` if spy was called at least once with the provided arguments and n

#### `spy.calledOnceWithExactly(arg1, arg2, ...);`

Returns `true` if spy was called exactly once and with only the provided arguments.
Returns `true` if spy was called exactly once in total and that one call was using the exact provided arguments and no others.


#### `spy.alwaysCalledWithExactly(arg1, arg2, ...);`
Expand Down Expand Up @@ -346,7 +346,7 @@ Returns `true` if spy always threw the provided exception object.

Returns `true` if spy returned the provided value at least once.

Uses deep comparison for objects and arrays. Use `spy.returned(sinon.match.same(obj))` for strict comparison (see [matchers][matchers]).
Uses deep comparison for objects and arrays. Use `spy.returned(sinon.match.same(obj))` for strict comparison (see [matchers](matchers)).


#### `spy.alwaysReturned(obj);`
Expand Down Expand Up @@ -436,4 +436,3 @@ Returns the passed format string with the following replacements performed:
</dl>

[call]: ../spy-call
[matchers]: ../matchers
6 changes: 2 additions & 4 deletions docs/_releases/latest/spy-call.md
Expand Up @@ -23,7 +23,7 @@ assertEquals("/stuffs", spyCall.args[0]);

### `spyCall.calledOn(obj);`

Returns `true` if `obj` was `this` for this call. `calledOn` also accepts a matcher `spyCall.calledOn(sinon.match(fn))` (see [matchers][matchers]).
Returns `true` if `obj` was `this` for this call. `calledOn` also accepts a matcher `spyCall.calledOn(sinon.match(fn))` (see [matchers](matchers)).


### `spyCall.calledWith(arg1, arg2, ...);`
Expand Down Expand Up @@ -56,7 +56,7 @@ This behaves the same as `spyCall.notCalledWith(sinon.match(arg1), sinon.match(a

Returns `true` if spied function returned the provided `value` on this call.

Uses deep comparison for objects and arrays. Use `spyCall.returned(sinon.match.same(obj))` for strict comparison (see [matchers][matchers]).
Uses deep comparison for objects and arrays. Use `spyCall.returned(sinon.match.same(obj))` for strict comparison (see [matchers](matchers)).

### `spyCall.threw();`

Expand Down Expand Up @@ -143,5 +143,3 @@ Exception thrown, if any.
### `spyCall.returnValue`

Return value.

[matchers]: ../matchers
25 changes: 22 additions & 3 deletions docs/_releases/latest/stubs.md
Expand Up @@ -76,8 +76,6 @@ Replaces `object.method` with a stub function. An exception is thrown if the pro

The original function can be restored by calling `object.method.restore();` (or `stub.restore();`).

Stubs can be used to replace a module's dependencies, ensuring it is tested in isolation. [For simple cases](../../_howto/stub-dependency.md) you might not need additional helper libraries, but for more complex cases you might need to [target the module loading mechanisms](../../link-seams-commonjs.md).

#### ~~`var stub = sinon.stub(object, "method", func);`~~

This has been removed from `v3.0.0`. Instead you should use
Expand All @@ -88,7 +86,7 @@ A [codemod is available](https://github.com/hurrymaplelad/sinon-codemod) to upgr

#### `var stub = sinon.stub(obj);`

Stubs all the object's methods. Use the `restore` utility to restore an object stubbed this way.
Stubs all the object's methods.

Note that it's usually better practice to stub individual methods, particularly on objects that you don't understand or control all the methods for (e.g. library dependencies).

Expand Down Expand Up @@ -407,6 +405,27 @@ obj.sum.callThrough();

obj.sum(2, 2); // 'bar'
obj.sum(1, 2); // 3


#### `stub.callThroughWithNew();`

Causes the original method wrapped into the stub to be called using the `new` operator when none of the conditional stubs are matched.

```javascript
var obj = {};
obj.Sum = function MyConstructor(a, b) {
this.result = a + b;
};
sinon
.stub(obj, 'Sum')
.callThroughWithNew()
.withArgs(1, 2)
.returns({ result: 9000 });
(new obj.Sum(2, 2)).result; // 4
(new obj.Sum(1, 2)).result; // 9000
```


Expand Down
51 changes: 51 additions & 0 deletions docs/_releases/v7.4.1.md
@@ -0,0 +1,51 @@
---
layout: page
title: API documentation - Sinon.JS
release_id: v7.4.1
---

# {{page.title}} - `{{page.release_id}}`

This page contains the entire Sinon.JS API documentation along with brief introductions to the concepts Sinon implements.

* [General setup](./general-setup)
* [Fakes](./fakes)
* [Spies](./spies)
* [Stubs](./stubs)
* [Mocks](./mocks)
* [Spy calls](./spy-call)
* [Fake timers](./fake-timers)
* [Fake <code>XHR</code> and server](./fake-xhr-and-server)
* [JSON-P](./json-p)
* [Assertions](./assertions)
* [Matchers](./matchers)
* [Sandboxes](./sandbox)
* [Utils](./utils)

{% include docs/migration-guides.md %}

### Compatibility

### ES5.1

Sinon `{{page.release_id}}` is written as [ES5.1][ES5] and requires no transpiler or polyfills to run in the runtimes listed below.

### Supported runtimes

`{{page.release_id}}` has been verified in these runtimes:

* Firefox 45
* Chrome 48
* Internet Explorer 11
* Edge 14
* Safari 9
* [Node.js LTS versions](https://github.com/nodejs/Release)

There should not be any issues with using Sinon `{{page.release_id}}` in newer versions of the same runtimes.

If you need to support very old runtimes that have incomplete support for [ES5.1][ES5] you might get away with using loading [`es5-shim`][es5-shim] in your test environment.

{% include docs/contribute.md %}

[ES5]: http://www.ecma-international.org/ecma-262/5.1/
[es5-shim]: https://github.com/es-shims/es5-shim

0 comments on commit dce58d4

Please sign in to comment.