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

New API: default sandbox and fake #1586

Closed
wants to merge 40 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
40 commits
Select commit Hold shift + click to select a range
ec50f81
Refactor sandbox to assimilate collection and remove collection
mroderick Sep 30, 2017
e88ca29
Export enhanced sandbox as sinon api
mroderick Oct 9, 2017
6dcb70d
Review: reword deprecation message to not mention sinon.Sandbox
mroderick Oct 12, 2017
43ae3e3
Add `fake`
mroderick Oct 25, 2017
983ea8b
Fixup: Improve tests of fake
mroderick Oct 26, 2017
b2a748b
Remove undesirable methods before returning fake
mroderick Oct 27, 2017
c306626
Fixup: bad merge
mroderick Nov 11, 2017
0e856cf
Extract isNonExistentOwnProperty to own function
mroderick Nov 11, 2017
8308738
Extract isRestorable to own file
mroderick Nov 11, 2017
4755de2
WIP
mroderick Dec 19, 2017
1974ce4
Extract isPropertyConfigurable to own file
mroderick Dec 28, 2017
1ea317a
Add replaceGetter and replaceSetter
mroderick Dec 28, 2017
cbbc566
Rename third argument to `replacement`
mroderick Dec 28, 2017
f06570d
Improve input validation of sandbox.replace* methods
mroderick Dec 28, 2017
37a3b98
Add documentation for sinon.replace and sinon.fake*
mroderick Dec 28, 2017
b378a06
Fix failing tests in Chromium
mroderick Dec 30, 2017
194f987
Clarify documentation
mroderick Dec 30, 2017
a0fbd28
Fix typo in documentation
mroderick Dec 30, 2017
6a51394
Extract nextTick to own file
mroderick Dec 31, 2017
4f3fa63
Add yields and yieldsTo to fake
mroderick Dec 31, 2017
60682fa
Improve language of fake documentation
mroderick Dec 31, 2017
a7fa009
Fix broken test in IE11
mroderick Jan 1, 2018
c188795
Simplify hasFunctionNameSupport
mroderick Jan 2, 2018
222a0c5
Docs: Added example for how to use `restore`
mroderick Jan 9, 2018
a994b5a
Docs: add migration guide for v5
mroderick Jan 9, 2018
10c04e8
Add postinstall banner pointing to Open Collective
mroderick Jan 11, 2018
fc0246b
Update History.md and AUTHORS for new release
mroderick Jan 11, 2018
85ceb18
5.0.0
mroderick Jan 11, 2018
d67d808
Add release documentation for v5.0.0
mroderick Jan 11, 2018
cd815d6
Update docs/changelog.md and set new release id in docs/_config.yml
mroderick Jan 11, 2018
f2ccca6
Remove deprecated spy.reset method
mroderick Jan 11, 2018
fac8ed5
Set new package version
mroderick Jan 11, 2018
7fd2ef0
Fixup: document removal of spy.reset in migration guide
mroderick Jan 11, 2018
9451299
Fixup: bad rebase
mroderick Jan 13, 2018
efbc9c5
Update History.md and AUTHORS for new release
mroderick Jan 16, 2018
607360f
5.0.0-next.2
mroderick Jan 16, 2018
0aaec00
Update History.md and AUTHORS for new release
mroderick Jan 16, 2018
66663da
5.0.0-next.3
mroderick Jan 16, 2018
2e2f632
Add release documentation for v5.0.0-next.3
mroderick Jan 16, 2018
5767a33
Update docs/changelog.md and set new release id in docs/_config.yml
mroderick Jan 16, 2018
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
38 changes: 38 additions & 0 deletions History.md
Original file line number Diff line number Diff line change
@@ -1,4 +1,42 @@

5.0.0-next-3 / 2018-01-16
==================

Publish next version including changes from 4.1.6


5.0.0-next / 2018-01-11
==================

* Add postinstall banner pointing to Open Collective
* Docs: add migration guide for v5
* Docs: Added example for how to use `restore`
* Simplify hasFunctionNameSupport
* Fix broken test in IE11
* Improve language of fake documentation
* Add yields and yieldsTo to fake
* Extract nextTick to own file
* Fix typo in documentation
* Clarify documentation
* Fix failing tests in Chromium
* Add documentation for sinon.replace and sinon.fake*
* Improve input validation of sandbox.replace* methods
* Rename third argument to `replacement`
* Add replaceGetter and replaceSetter
* Extract isPropertyConfigurable to own file
* WIP
* Extract isRestorable to own file
* Extract isNonExistentOwnProperty to own function
* Fixup: bad merge
* Remove undesirable methods before returning fake
* Fixup: Improve tests of fake
* Add `fake`
* Review: reword deprecation message to not mention sinon.Sandbox
* Export enhanced sandbox as sinon api
* Refactor sandbox to assimilate collection and remove collection
* Update docs/changelog.md and set new release id in docs/_config.yml
* Add release documentation for v4.1.4

4.4.1 / 2018-02-24
==================

Expand Down
2 changes: 1 addition & 1 deletion docs/_config.yml
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ description: >-
url: 'http://sinonjs.org'
github_username: sinonjs
sinon:
current_release: v4.4.1
current_release: v5.0.0-next.3
markdown: kramdown
kramdown:
input: GFM
Expand Down
49 changes: 49 additions & 0 deletions docs/_releases/v5.0.0-next.3.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
---
layout: page
title: API documentation - Sinon.JS
release_id: v5.0.0-next.3
---

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

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

* [Spies](./spies)
* [Stubs](./stubs)
* [Mocks](./mocks)
* [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 4

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. If that fails, we recommend [getting a legacy releases of Sinon][legacy-site].

{% include docs/contribute.md %}

[ES5]: http://www.ecma-international.org/ecma-262/5.1/
[es5-shim]: https://github.com/es-shims/es5-shim
[legacy-site]: http://legacy.sinonjs.org
190 changes: 190 additions & 0 deletions docs/_releases/v5.0.0-next.3/assertions.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,190 @@
---
layout: page
title: Assertions - Sinon.JS
breadcrumb: assertions
---

Sinon.JS ships with a set of assertions that mirror most behavior verification methods and properties on spies and stubs. The advantage of using the assertions is that failed expectations on stubs and spies can be expressed directly as assertion failures with detailed and helpful error messages.

To make sure assertions integrate nicely with your test framework, you should customize either `sinon.assert.fail` or `sinon.assert.failException` and look into `sinon.assert.expose` and `sinon.assert.pass`.

The assertions can be used with either spies or stubs.

```javascript
"test should call subscribers with message as first argument" : function () {
var message = "an example message";
var spy = sinon.spy();

PubSub.subscribe(message, spy);
PubSub.publishSync(message, "some payload");

sinon.assert.calledOnce(spy);
sinon.assert.calledWith(spy, message);
}
```

## Assertions API

#### `sinon.assert.fail(message)`

Every assertion fails by calling this method.

By default it throws an error of type `sinon.assert.failException`.

If the test framework looks for assertion errors by checking for a specific exception, you can simply override the kind of exception thrown. If that does not fit with your testing framework of choice, override the `fail` method to do the right thing.


#### `sinon.assert.failException;`

Defaults to `AssertError`.


#### `sinon.assert.pass(assertion);`

Called every time `assertion` passes.

Default implementation does nothing.


#### `sinon.assert.notCalled(spy);`

Passes if `spy` was never called

#### `sinon.assert.called(spy);`

Passes if `spy` was called at least once.


#### `sinon.assert.calledOnce(spy);`

Passes if `spy` was called once and only once.


#### `sinon.assert.calledTwice(spy);`

Passes if `spy` was called exactly twice.


#### `sinon.assert.calledThrice(spy)`

Passes if `spy` was called exactly three times.


#### `sinon.assert.callCount(spy, num)`
Passes if `spy` was called exactly `num` times.


#### `sinon.assert.callOrder(spy1, spy2, ...)`
Passes if provided spies were called in the specified order.


#### `sinon.assert.calledOn(spy, obj)`

Passes if `spy` was ever called with `obj` as its `this` value.


#### `sinon.assert.alwaysCalledOn(spy, obj)`

Passes if `spy` was always called with `obj` as its `this` value.


#### `sinon.assert.calledWith(spy, arg1, arg2, ...);`

Passes if `spy` was called with the provided arguments.


#### `sinon.assert.alwaysCalledWith(spy, arg1, arg2, ...);`

Passes if `spy` was always called with the provided arguments.


#### `sinon.assert.neverCalledWith(spy, arg1, arg2, ...);`

Passes if `spy` was never called with the provided arguments.


#### `sinon.assert.calledWithExactly(spy, arg1, arg2, ...);`

Passes if `spy` was called with the provided arguments and no others.


#### `sinon.assert.alwaysCalledWithExactly(spy, arg1, arg2, ...);`

Passes if `spy` was always called with the provided arguments and no others.


#### `sinon.assert.calledWithMatch(spy, arg1, arg2, ...)`

Passes if `spy` was called with matching arguments.

This behaves the same way as `sinon.assert.calledWith(spy, sinon.match(arg1), sinon.match(arg2), ...)`.


#### `sinon.assert.alwaysCalledWithMatch(spy, arg1, arg2, ...)`

Passes if `spy` was always called with matching arguments.

This behaves the same way as `sinon.assert.alwaysCalledWith(spy, sinon.match(arg1), sinon.match(arg2), ...)`.


#### `sinon.assert.calledWithNew(spy)`

Passes if `spy` was called with the `new` operator.


#### `sinon.assert.neverCalledWithMatch(spy, arg1, arg2, ...)`

Passes if `spy` was never called with matching arguments.

This behaves the same way as `sinon.assert.neverCalledWith(spy, sinon.match(arg1), sinon.match(arg2), ...)`.


#### `sinon.assert.threw(spy, exception);`

Passes if `spy` threw the given exception.

The exception can be a `String` denoting its type, or an actual object.

If only one argument is provided, the assertion passes if `spy` ever threw any exception.


#### `sinon.assert.alwaysThrew(spy, exception);`

Like above, only required for all calls to the spy.

#### `sinon.assert.match(actual, expectation);`

Uses [`sinon.match`](../matchers) to test if the arguments can be considered a match.

```javascript
var sinon = require('sinon');

describe('example', function(){
it('should match on `x` property, and ignore `y` property', function() {
var expected = {x: 1},
actual = {x: 1, y: 2};

sinon.assert.match(actual, expected);
});
});
```

#### `sinon.assert.expose(object, options);`

Exposes assertions into another object, to better integrate with the test framework. For instance, JsTestDriver uses global assertions, and to make Sinon.JS assertions appear alongside them, you can do.

```javascript
sinon.assert.expose(this);
```

This will give you `assertCalled(spy)`,`assertCallOrder(spy1, spy2, ...)` and so on.

The method accepts an optional options object with two options.

<dl>
<dt>prefix</dt>
<dd>is a prefix to give assertions. By default it is "assert", so <code>sinon.assert.called</code> becomes <code>target.assertCalled</code>. By passing a blank string, the exposed method will be <code>target.called</code>.</dd>

<dt>includeFail</dt>
<dd><code>true</code> by default, copies over the <code>fail</code> and <code>failException</code> properties</dd>
</dl>
Loading