unexpected
Advanced tools
Comparing version 5.0.0-beta15 to 5.0.0-beta16
@@ -14,20 +14,16 @@ # Development | ||
* *src/unexpected-license.js*:<br> | ||
The license file | ||
* *src/unexpected-namespace.js*:<br> | ||
The internal namespace definition | ||
* *src/unexpected-es4-compatible.js*:<br> | ||
ES5 functions shimmed to work in a ES4 compatible environment | ||
* *src/unexpected-utils.js*:<br> | ||
* *lib/index.js*:<br> | ||
The entry point for the library. | ||
* *lib/Unexpected.js*:<br> | ||
The core of the library. | ||
* *lib/Assertion.js*:<br> | ||
The class that assertions are instantiated from. | ||
* *lib/utils.js*:<br> | ||
Utility functions | ||
* *src/unexpected-equal.js*:<br> | ||
Deep-equality | ||
* *src/unexpected-inspect.js*:<br> | ||
Object inspect | ||
* *src/unexpected-core.js*:<br> | ||
The core part of Unexpected | ||
* *src/unexpected-assertions.js*:<br> | ||
The core assertions provided by Unexpected | ||
* *src/unexpected-module.js*:<br> | ||
The module definitions | ||
* *lib/styles.js*:<br> | ||
MagicPen styles for controling the output. | ||
* *lib/types.js*:<br> | ||
Type definitions for every type Unexpected understands. | ||
* *lib/assertions.js*:<br> | ||
All assertions that is included in the core library. | ||
@@ -38,3 +34,3 @@ ## Running tests in the console | ||
make test | ||
make test-production | ||
make test-phantomjs | ||
``` | ||
@@ -41,0 +37,0 @@ |
@@ -84,3 +84,3 @@ var utils = require('./utils'); | ||
expect.addAssertion(['string', 'arrayLike', 'object'], 'to be (the empty|an empty|a non-empty) (string|array|object)', function (expect, subject) { | ||
expect.addAssertion(['string', 'arrayLike'], 'to be (the empty|an empty|a non-empty) (string|array)', function (expect, subject) { | ||
expect(subject, 'to be a', this.alternations[1]); | ||
@@ -197,3 +197,3 @@ expect(subject, this.alternations[0] === 'a non-empty' ? 'not to be empty' : 'to be empty'); | ||
expect.addAssertion(['string', 'object'], 'to be non-empty', function (expect, subject) { | ||
expect.addAssertion(['string', 'arrayLike'], 'to be non-empty', function (expect, subject) { | ||
expect(subject, 'not to be empty'); | ||
@@ -365,2 +365,6 @@ }); | ||
expect.addAssertion('function', 'to have arity', function (expect, subject, value) { | ||
expect(subject.length, 'to equal', value); | ||
}); | ||
expect.addAssertion('object', 'to be (a|an) [non-empty] (map|hash|object) whose values satisfy', function (expect, subject) { | ||
@@ -374,3 +378,3 @@ var extraArgs = Array.prototype.slice.call(arguments, 2); | ||
if (this.flags['non-empty']) { | ||
expect(subject, 'to be non-empty'); | ||
expect(subject, 'not to equal', {}); | ||
} | ||
@@ -452,3 +456,3 @@ this.errorMode = 'bubble'; | ||
if (this.flags['non-empty']) { | ||
expect(subject, 'to be non-empty'); | ||
expect(subject, 'not to equal', {}); | ||
} | ||
@@ -703,2 +707,6 @@ this.errorMode = 'bubble'; | ||
}); | ||
expect.addAssertion('functionInvocation', 'to produce output satisfying', function (expect, subject) { | ||
expect.apply(expect, [subject[0].apply(subject, subject.slice(1)), 'to satisfy assertion'].concat(Array.prototype.slice.call(arguments, 2))); | ||
}); | ||
}; |
@@ -6,2 +6,5 @@ var Unexpected = require('./Unexpected'); | ||
.installPlugin(require('./types')) | ||
.installPlugin(function (expect) { | ||
expect.output.installPlugin(require('magicpen-prism')); | ||
}) | ||
.installPlugin(require('./assertions')); |
@@ -301,9 +301,17 @@ var utils = require('./utils'); | ||
}, | ||
prefix: function (output) { | ||
return output.text('['); | ||
}, | ||
suffix: function (output) { | ||
return output.text(']'); | ||
}, | ||
inspect: function (arr, depth, output, inspect) { | ||
var prefixOutput = this.prefix(output.clone(), arr); | ||
var suffixOutput = this.suffix(output.clone(), arr); | ||
if (arr.length === 0) { | ||
return output.text('[]'); | ||
return output.append(prefixOutput).append(suffixOutput); | ||
} | ||
if (depth === 1) { | ||
return output.text('[...]'); | ||
return output.append(prefixOutput).text('...').append(suffixOutput); | ||
} | ||
@@ -334,3 +342,3 @@ | ||
if (multipleLines) { | ||
output.text('[').nl().indentLines(); | ||
output.append(prefixOutput).nl().indentLines(); | ||
@@ -341,5 +349,5 @@ inspectedItems.forEach(function (inspectedItem, index) { | ||
output.outdentLines().text(']'); | ||
output.outdentLines().append(suffixOutput); | ||
} else { | ||
output.text('[ '); | ||
output.append(prefixOutput).sp(); | ||
inspectedItems.forEach(function (inspectedItem, index) { | ||
@@ -352,3 +360,3 @@ output.append(inspectedItem); | ||
}); | ||
output.text(' ]'); | ||
output.sp().append(suffixOutput); | ||
} | ||
@@ -409,8 +417,12 @@ return output; | ||
removedItems = 0; | ||
actual.forEach(function (_, index) { | ||
removedItems += removesByIndex[index] || 0; | ||
removeTable[index] = removedItems; | ||
}); | ||
function updateRemoveTable() { | ||
removedItems = 0; | ||
actual.forEach(function (_, index) { | ||
removedItems += removesByIndex[index] || 0; | ||
removeTable[index] = removedItems; | ||
}); | ||
} | ||
updateRemoveTable(); | ||
var moves = itemsDiff.filter(function (diffItem) { | ||
@@ -433,10 +445,5 @@ return diffItem.type === 'move'; | ||
removesByIndex[diffItem.from] = movedItems; | ||
updateRemoveTable(); | ||
}); | ||
removedItems = 0; | ||
actual.forEach(function (_, index) { | ||
removedItems += removesByIndex[index] || 0; | ||
removeTable[index] = removedItems; | ||
}); | ||
var inserts = itemsDiff.filter(function (diffItem) { | ||
@@ -465,5 +472,4 @@ return diffItem.type === 'insert'; | ||
}); | ||
output.append(this.prefix(output.clone())).nl().indentLines(); | ||
output.text('[').nl().indentLines(); | ||
mutatedArray.forEach(function (diffItem, index) { | ||
@@ -500,3 +506,3 @@ output.i().block(function () { | ||
output.outdentLines().text(']'); | ||
output.outdentLines().append(this.suffix(output.clone())); | ||
@@ -518,2 +524,8 @@ return result; | ||
base: 'arrayLike', | ||
prefix: function (output) { | ||
return output.text('arguments(', 'cyan'); | ||
}, | ||
suffix: function (output) { | ||
return output.text(')', 'cyan'); | ||
}, | ||
identify: function (obj) { | ||
@@ -819,2 +831,24 @@ return Object.prototype.toString.call(obj) === '[object Arguments]'; | ||
}); | ||
expect.addType({ | ||
name: 'functionInvocation', | ||
base: 'array', | ||
identify: function (obj) { | ||
return this.baseType.identify(obj) && obj.length > 0 && typeof obj[0] === 'function'; | ||
}, | ||
inspect: function (obj, depth, output, inspect) { | ||
var inspector = Object.create(this.baseType); | ||
inspector.prefix = function (output) { | ||
return output.code((obj[0].name || 'anonymous') + '(', 'javascript'); | ||
}; | ||
inspector.suffix = function (output) { | ||
return output.code(')', 'javascript'); | ||
}; | ||
return inspector.inspect(obj.slice(1), depth, output, inspect); | ||
}, | ||
equal: function (a, b, equal) { | ||
return equal(a[0], b[0]) && equal(a.slice(1), b.slice(1)); | ||
} | ||
}); | ||
}; |
@@ -530,2 +530,3 @@ /*global window*/ | ||
wrappedExpect.format = this.format; | ||
wrappedExpect.it = this.it.bind(this); | ||
@@ -532,0 +533,0 @@ var args = Array.prototype.slice.call(arguments, 2); |
{ | ||
"name": "unexpected", | ||
"version": "5.0.0-beta15", | ||
"version": "5.0.0-beta16", | ||
"author": "Sune Sloth Simonsen <sune@we-knowhow.dk>", | ||
@@ -5,0 +5,0 @@ "keywords": [ |
110
README.md
# Unexpected | ||
Minimalistic BDD assertion toolkit inspired by | ||
Extensible BDD assertion toolkit inspired by | ||
[expect.js](https://github.com/LearnBoost/expect.js) | ||
@@ -19,3 +19,3 @@ | ||
[Run the test in the browser](http://sunesimonsen.github.io/unexpected/test/tests.production.html) | ||
[Run the test in the browser](http://sunesimonsen.github.io/unexpected/test/tests.html) | ||
@@ -176,7 +176,3 @@ ## Features | ||
expect(NaN, 'to be NaN'); | ||
expect({}, 'to be NaN'); | ||
expect(2, 'not to be NaN'); | ||
expect(null, 'not to be NaN'); | ||
expect(undefined, 'to be NaN'); | ||
expect("String", 'to be NaN'); | ||
``` | ||
@@ -210,3 +206,2 @@ | ||
expect('hello world', 'to contain', 'world'); | ||
expect(null, 'not to contain', 'world'); | ||
``` | ||
@@ -222,3 +217,3 @@ | ||
**empty**: asserts that an array is empty or not | ||
**empty**: asserts that an array or array-like object (identified by the presence of a `length` property) is empty | ||
@@ -228,6 +223,5 @@ ```js | ||
expect('', 'to be empty'); | ||
expect({}, 'to be empty'); | ||
expect({ length: 0, duck: 'typing' }, 'to be empty'); | ||
expect({ my: 'object' }, 'not to be empty'); | ||
expect([1,2,3], 'not to be empty'); | ||
expect({ length: 0, duck: 'typing' }, 'to be empty'); | ||
``` | ||
@@ -252,3 +246,3 @@ | ||
expect({ a: 'a', b: { c: 'c' }, d: 'd' }, 'to have own properties', ['a', 'b']); | ||
expect({ a: 'a', b: { c: 'c' }, d: 'd' }, 'to not have properties', ['k', 'l']); | ||
expect({ a: 'a', b: { c: 'c' }, d: 'd' }, 'not to have properties', ['k', 'l']); | ||
expect({ a: 'a', b: { c: 'c' }, d: 'd' }, 'to have properties', { | ||
@@ -267,3 +261,2 @@ a: 'a', | ||
```js | ||
expect(null, 'not to have key', 'a'); | ||
expect({ a: 'b' }, 'to have key', 'a'); | ||
@@ -290,2 +283,8 @@ expect({ a: 'b' }, 'not to have key', 'b'); | ||
**arity**: asserts that the `Function` takes the given number of arguments | ||
```js | ||
expect(Math.max, 'to have arity', 2); | ||
``` | ||
**finite/infinite**: asserts a finite or infinite number | ||
@@ -297,3 +296,2 @@ | ||
expect(Infinity, 'to be infinite'); | ||
expect(false, 'not to be infinite'); | ||
``` | ||
@@ -365,3 +363,3 @@ | ||
**array whose items satify**: will run an assertion function for each items in an array | ||
**array whose items satisfy**: will run an assertion function for each items in an array | ||
@@ -383,3 +381,3 @@ ```js | ||
Using this assertion result in very detailed error reporting show in the below example: | ||
Using this assertion result in very detailed error reporting as shown in the below example: | ||
@@ -399,12 +397,44 @@ ```js | ||
failed expectation in [ [ 0, 1, 2 ], [ 4, '5', 6 ], [ 7, 8, '9' ] ]: | ||
1: failed expectation in [ 4, '5', 6 ]: | ||
1: expected '5' to be a 'number' | ||
2: failed expectation in [ 7, 8, '9' ]: | ||
2: expected '9' to be a 'number' | ||
1: failed expectation in [ 4, '5', 6 ]: | ||
1: expected '5' to be a number | ||
2: failed expectation in [ 7, 8, '9' ]: | ||
2: expected '9' to be a number | ||
``` | ||
**map whose keys satify**: will run an assertion function for each key in a map | ||
**satisfy**: match against a spec | ||
All properties and nested objects mentioned in the right-hand side object are | ||
required to be present. Primitive values are compared with `to equal` semantics: | ||
```js | ||
expect({ hey: { there: true } }, 'to satisfy', { hey: {} }); | ||
``` | ||
To disallow additional properties in the subject, use `to exhaustively satisfy`: | ||
```js | ||
expect({ hey: { there: true } }, 'to exhaustively satisfy', { hey: { there: true } }); | ||
``` | ||
Regular expressions and functions in the right-hand side object will be run | ||
against the corresponding values in the subject: | ||
```js | ||
expect({ bar: 'quux', baz: true }, 'to satisfy', { bar: /QU*X/i }); | ||
``` | ||
Can be combined with `expect.it` to create complex specifications that delegate to | ||
existing assertions: | ||
```js | ||
expect({foo: 123, baz: 'bogus'}, 'to satisfy', { | ||
foo: expect.it('to be a number').and('to be greater than', 10), | ||
baz: expect.it('not to match', /^boh/) | ||
}); | ||
``` | ||
**map whose keys satisfy**: will run an assertion function for each key in a map | ||
```js | ||
expect({ foo: 0, bar: 1, baz: 2, qux: 3 }, | ||
@@ -420,3 +450,3 @@ 'to be a map whose keys satisfy', function (key) { | ||
Using this assertion result in very detailed error reporting show in the below example: | ||
Using this assertion result in very detailed error reporting as shown in the below example: | ||
@@ -434,6 +464,6 @@ ```js | ||
failed expectation on keys foo, bar, baz, qux, quux: | ||
quux: expected 'quux' to have length 3 | ||
quux: expected 'quux' to have length 3 | ||
``` | ||
**map whose values satify**: will run an assertion function for each value in a map | ||
**map whose values satisfy**: will run an assertion function for each value in a map | ||
@@ -451,3 +481,3 @@ ```js | ||
Using this assertion result in very detailed error reporting show in the below example: | ||
Using this assertion result in very detailed error reporting as shown in the below example: | ||
@@ -467,9 +497,11 @@ ```js | ||
failed expectation in | ||
{ foo: [ 0, 1, 2 ], | ||
{ | ||
foo: [ 0, 1, 2 ], | ||
bar: [ 4, '5', 6 ], | ||
baz: [ 7, 8, '9' ] }: | ||
bar: failed expectation in [ 4, '5', 6 ]: | ||
1: expected '5' to be a 'number' | ||
baz: failed expectation in [ 7, 8, '9' ]: | ||
2: expected '9' to be a 'number' | ||
baz: [ 7, 8, '9' ] | ||
}: | ||
bar: failed expectation in [ 4, '5', 6 ]: | ||
1: expected '5' to be a number | ||
baz: failed expectation in [ 7, 8, '9' ]: | ||
2: expected '9' to be a number | ||
``` | ||
@@ -586,3 +618,3 @@ | ||
expected [ 4, 3, 1, 2 ] to be sorted | ||
expected [ 4, 3, 1, 2 ] to equal [ 1, 2, 3, 4 ] | ||
expected [ 4, 3, 1, 2 ] to equal [ 1, 2, 3, 4 ] | ||
``` | ||
@@ -593,3 +625,3 @@ | ||
[unexpected-assertions.js](https://github.com/sunesimonsen/unexpected/blob/master/lib/unexpected-assertions.js) | ||
[lib/assertions.js](https://github.com/sunesimonsen/unexpected/blob/master/lib/assertions.js) | ||
@@ -631,9 +663,11 @@ ### expect.installPlugin(plugin) | ||
```js | ||
describe('test suite', function () { | ||
it('should expose a function', function () { | ||
expect(add, 'to be a', 'function'); | ||
}); | ||
describe('math.js', function () { | ||
describe('add', function () { | ||
it('is a function', function () { | ||
expect(add, 'to be a', 'function'); | ||
}); | ||
it('should do math', function () { | ||
expect(add(1, 3), 'to be', 4); | ||
it('does addition on numbers', function () { | ||
expect(add(1, 3), 'to be', 4); | ||
}); | ||
}); | ||
@@ -640,0 +674,0 @@ }); |
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is too big to display
Sorry, the diff of this file is too big to display
Uses eval
Supply chain riskPackage uses dynamic code execution (e.g., eval()), which is a dangerous practice. This can prevent the code from running in certain environments and increases the risk that the code may contain exploits or malicious behavior.
Found 1 instance in 1 package
1243266
16278
673
35
1