@sinonjs/referee
Advanced tools
Comparing version 2.5.2 to 2.6.0
@@ -358,2 +358,32 @@ (function (global, factory) { | ||
function addHasArity(referee) { | ||
referee.add("hasArity", { | ||
assert: function assert(actual, expected) { | ||
if (typeof actual !== "function") { | ||
throw new TypeError( | ||
'hasArity expects "actual" argument to be a Function' | ||
); | ||
} | ||
if (typeof expected !== "number" || expected < 0) { | ||
throw new TypeError( | ||
'hasArity expected "expected" argument to be a non-negative Number' | ||
); | ||
} | ||
this.arity = actual.length; | ||
this.name = actual.name; | ||
return this.arity === expected; | ||
}, | ||
assertMessage: | ||
"Expected ${name} to have arity of ${1} but was ${arity}", | ||
refuteMessage: "Expected ${name} to not have arity of ${1}", | ||
expectation: "toHaveArity", | ||
values: actualAndExpectedMessageValues_1 | ||
}); | ||
} | ||
var hasArity = addHasArity; | ||
var hasPrototype = function(referee) { | ||
@@ -1511,2 +1541,3 @@ referee.add("hasPrototype", { | ||
greater(referee); | ||
hasArity(referee); | ||
hasPrototype(referee); | ||
@@ -1513,0 +1544,0 @@ isArray(referee); |
@@ -8,3 +8,15 @@ # referee | ||
## Install | ||
```shell | ||
npm install @sinonjs/referee --save-dev | ||
``` | ||
### [Sinon.JS](https://sinonjs.org) integration | ||
You can extend **referee** with assertions that integrates with [Sinon.JS](https://sinonjs.org) | ||
See [referee-sinon](https://github.com/sinonjs/referee-sinon) | ||
## Assertions and refutations | ||
@@ -65,20 +77,44 @@ | ||
*Overview:* | ||
### Overview | ||
#### Any | ||
* [`defined()`](#defined) | ||
* [`equals()`](#equals) | ||
* [`match()`](#match) | ||
* [`same()`](#same) | ||
* [`equals()`](#equals) | ||
#### String | ||
* [`json()`](#json) | ||
* [`matchJson()`](#matchjson) | ||
#### Number | ||
* [`greater()`](#greater) | ||
* [`less()`](#less) | ||
* [`defined()`](#defined) | ||
* [`isNull()`](#isnull) | ||
* [`match()`](#match) | ||
* [`near()`](#near) | ||
#### Function | ||
* [`exception()`](#exception) | ||
* [`near()`](#near) | ||
* [`hasArity()`](#hasarity) | ||
#### Object | ||
* [`hasPrototype()`](#hasprototype) | ||
#### Array and array like | ||
* [`contains()`](#contains) | ||
#### DOM element | ||
* [`tagName()`](#tagname) | ||
* [`className()`](#classname) | ||
* [`json()`](#json) | ||
* [`matchJson()`](#matchjson) | ||
#### Types and values | ||
These assertions are for checking for built-in types and values. | ||
* [`isNull()`](#isnull) | ||
* [`isArray()`](#isarray) | ||
@@ -1274,3 +1310,3 @@ * [`isArrayBuffer()`](#isarraybuffer) | ||
Fails if `callback` does not throw an exception. If the optional `matcher` is provided, the assertion fails if the callback either does not throw an exception, or if the exception does not meet the criterias of the given `matcher. | ||
Fails if `callback` does not throw an exception. If the optional `matcher` is provided, the assertion fails if the callback either does not throw an exception, or if the exception does not meet the criterias of the given `matcher`. | ||
@@ -1348,2 +1384,23 @@ The `matcher` can be of type `object` or `function`. If the `matcher` is of type `object`, the captured error object and the `matcher` are passed to [`match()`](#match). | ||
### `hasArity()` | ||
```js | ||
assert.hasArity(actual, arity[, message]) | ||
``` | ||
Fails when `actual` does not have the desired arity. | ||
```js | ||
assert.hasArity(function(one) {return one}, 1); // Passes | ||
assert.hasArity(function(one, two) {return one + two}, 2); // Passes | ||
assert.hasArity(function(one, two) {return one + two}, 1); // Fails | ||
``` | ||
#### Messages | ||
```js | ||
assert.hasArity.message = "Expected ${name} to have arity of ${1} but was ${arity}"; | ||
refute.hasArity.message = "Expected ${name} to not have arity of ${1}"; | ||
``` | ||
### `hasPrototype()` | ||
@@ -1527,3 +1584,3 @@ | ||
`referee` is an event-emitter. Listen to events with `on`: | ||
**referee** is an event-emitter. Listen to events with `on`: | ||
@@ -1557,12 +1614,5 @@ ```js | ||
## [Sinon.JS](https://sinonjs.org) integration | ||
You can extend `referee` with assertions that integrates with [Sinon.JS](https://sinonjs.org) | ||
See [referee-sinon](https://github.com/sinonjs/referee-sinon) | ||
## Expectations | ||
All of referee's assertions and refutations are also exposed as "expectations". Expectations is just a slightly different front-end to the same functionality, often preferred by the BDD inclined. | ||
All of **referee**'s assertions and refutations are also exposed as "expectations". Expectations is just a slightly different front-end to the same functionality, often preferred by the BDD inclined. | ||
@@ -1635,3 +1685,3 @@ Expectations mirror assertions under different names. Refutations can be expressed using `expect(obj).not` and then calling either of the expectations on the resulting object. | ||
### `expect.toBeObject()`` | ||
### `expect.toBeObject()` | ||
@@ -1846,3 +1896,3 @@ ```js | ||
Example: To use `referee with JsTestDriver, you can simply configure it as follows: | ||
Example: To use **referee** with JsTestDriver, you can simply configure it as follows: | ||
@@ -1955,3 +2005,3 @@ ```js | ||
<dl> | ||
<dt>`name`:</dt> | ||
<dt>name</dt> | ||
<dd>The name of the new assertion/refutation</dd> | ||
@@ -1961,21 +2011,21 @@ <dt>options</dt> | ||
<dl> | ||
<dt>`assert`:</dt> | ||
<dt><code>assert</code></dt> | ||
<dd> | ||
The verification function. Should return `true` when the assertion passes. The generated refutation will pass when the function returns `false`. | ||
The verification function. Should return <code>true</code> when the assertion passes. The generated refutation will pass when the function returns <code>false</code>. | ||
In some cases the refutation may not be the exact opposite of the assertion. If that is the case you should provide `options.refute` for the custom refutation. | ||
In some cases the refutation may not be the exact opposite of the assertion. If that is the case you should provide <code>options.refute</code> for the custom refutation. | ||
The number of formal parameters the function accepts determines the number of required arguments to the function. If the assertion is called with less arguments than expected, referee will fail it before your custom function is even called. | ||
The number of formal parameters the function accepts determines the number of required arguments to the function. If the assertion is called with less arguments than expected, <strong>referee</strong> will fail it before your custom function is even called. | ||
All arguments are available for interpolation into the resulting error message. The first argument will be available as `"${0}"`, the second as `"${1}"` and so on. If you want to embed other values than exact arguments into the string, you can set properties on this in the custom assertion, and refer to them as `"${name}"` in the message. | ||
All arguments are available for interpolation into the resulting error message. The first argument will be available as <code>"${0}"</code>, the second as <code>"${1}"</code> and so on. If you want to embed other values than exact arguments into the string, you can set properties on this in the custom assertion, and refer to them as <code>"${name}"</code> in the message. | ||
</dd> | ||
<dt>`refute`:</dt> | ||
<dd>Custom refutation function. Used over `!assert()` if provided.</dd> | ||
<dt>`assertMessage`:</dt> | ||
<dd>The error message to use when the assertion fails. The message may refer to arguments through switches like `"${0}"`` and so on (see above, under the assert argument). The message is exposed on the generated assertion as the property `assert.[name].message`.</dd> | ||
<dt>`refuteMessage`:</dt> | ||
<dd>Like `assertMessage`, but for refutations. Exposed as `refute.[name].message`.</dd> | ||
<dt>`values:`</dt> | ||
<dd>A function that maps values to be interpolated into the failure messages. This can be used when you need something more/else than the actual `arguments` in order.</dd> | ||
<dt>expectation:</dt> | ||
<dt><code>refute</code></dt> | ||
<dd>Custom refutation function. Used over <code>!assert()</code> if provided.</dd> | ||
<dt><code>assertMessage</code></dt> | ||
<dd>The error message to use when the assertion fails. The message may refer to arguments through switches like <code>"${0}"</code> and so on (see above, under the assert argument). The message is exposed on the generated assertion as the property <code>assert.[name].message</code>.</dd> | ||
<dt><code>refuteMessage</code></dt> | ||
<dd>Like <code>assertMessage</code>, but for refutations. Exposed as <code>refute.[name].message</code>.</dd> | ||
<dt><code>values</code></dt> | ||
<dd>A function that maps values to be interpolated into the failure messages. This can be used when you need something more/else than the actual <code>arguments</code> in order.</dd> | ||
<dt><code>expectation</code></dt> | ||
<dd>The name of the assertion as an expectation, e.g. “toBeSomething”. Optional.</dd> | ||
@@ -1994,3 +2044,3 @@ </dl> | ||
### `referee.throwOnFailure | ||
### `referee.throwOnFailure` | ||
@@ -1997,0 +2047,0 @@ `Boolean`. |
@@ -243,2 +243,3 @@ "use strict"; | ||
require("./assertions/greater")(referee); | ||
require("./assertions/has-arity")(referee); | ||
require("./assertions/has-prototype")(referee); | ||
@@ -245,0 +246,0 @@ require("./assertions/is-array")(referee); |
{ | ||
"name": "@sinonjs/referee", | ||
"version": "2.5.2", | ||
"version": "2.6.0", | ||
"description": "Assertions for any JavaScript test framework and environment", | ||
@@ -5,0 +5,0 @@ "author": "Christian Johansen", |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
167490
73
2963