Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

unexpected

Package Overview
Dependencies
Maintainers
2
Versions
330
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

unexpected - npm Package Compare versions

Comparing version 1.0.10 to 1.0.11

62

lib/unexpected.js

@@ -412,3 +412,3 @@ // Copyright (c) 2013 Sune Simonsen <sune@we-knowhow.dk>

forEach(['string', 'array'], function (type) {
forEach(['string', 'array', 'object'], function (type) {
expect.addAssertion('to be (the|an) empty ' + type, function () {

@@ -464,2 +464,6 @@ expect(this.obj, 'to be a', type);

expect.addAssertion('to be non-empty', function () {
expect(this.obj, 'not to be empty');
});
expect.addAssertion('to [not] [only] have (key|keys)', '[not] to have (key|keys)', function (keys) {

@@ -594,7 +598,18 @@ var obj = this.obj;

expect.addAssertion('to be a map whose values satisfy', function (callback) {
if ('function' !== typeof callback) {
expect.addAssertion('to be (a|an) [non-empty] (map|hash|object) whose values satisfy', function (callbackOrString) {
var callback;
if ('function' === typeof callbackOrString) {
callback = callbackOrString;
} else if ('string' === typeof callbackOrString) {
var args = Array.prototype.slice.call(arguments);
callback = function (value) {
expect.apply(expect, [value].concat(args));
};
} else {
throw new Error('Assertions "' + this.testDescription + '" expects a functions as argument');
}
expect(this.obj, 'to be an object');
if (this.flags['non-empty']) {
expect(this.obj, 'to be non-empty');
}

@@ -620,15 +635,48 @@ var obj = this.obj;

expect.addAssertion('to be an array whose items satisfy', function (callback) {
if ('function' !== typeof callback) {
expect.addAssertion('to be (a|an) [non-empty] array whose items satisfy', function (callbackOrString) {
var callback;
if ('function' === typeof callbackOrString) {
callback = callbackOrString;
} else if ('string' === typeof callbackOrString) {
var args = Array.prototype.slice.call(arguments);
callback = function (item) {
expect.apply(expect, [item].concat(args));
};
} else {
throw new Error('Assertions "' + this.testDescription + '" expects a functions as argument');
}
expect(this.obj, 'to be an array');
if (this.flags['non-empty']) {
expect(this.obj, 'to be non-empty');
}
expect(this.obj, 'to be a map whose values satisfy', callback);
});
expect.addAssertion('to be a map whose keys satisfy', function (callback) {
if ('function' !== typeof callback) {
['string', 'number', 'boolean', 'array', 'object', 'function', 'regexp', 'regex', 'regular expression'].forEach(function (type) {
expect.addAssertion('to be (a|an) [non-empty] array of ' + type + 's', function () {
expect(this.obj, 'to be an array whose items satisfy', function (item) {
expect(item, 'to be a', type);
});
if (this.flags['non-empty']) {
expect(this.obj, 'to be non-empty');
}
});
});
expect.addAssertion('to be (a|an) [non-empty] (map|hash|object) whose keys satisfy', function (callbackOrString) {
var callback;
if ('function' === typeof callbackOrString) {
callback = callbackOrString;
} else if ('string' === typeof callbackOrString) {
var args = Array.prototype.slice.call(arguments);
callback = function (key) {
expect.apply(expect, [key].concat(args));
};
} else {
throw new Error('Assertions "' + this.testDescription + '" expects a functions as argument');
}
expect(this.obj, 'to be an object');
if (this.flags['non-empty']) {
expect(this.obj, 'to be non-empty');
}

@@ -635,0 +683,0 @@ var obj = this.obj;

2

package.json
{
"name": "unexpected",
"version": "1.0.10",
"version": "1.0.11",
"author": "Sune Sloth Simonsen <sune@we-knowhow.dk>",

@@ -5,0 +5,0 @@ "keywords": [

@@ -136,4 +136,6 @@ # Unexpected

expect([], 'to be an', 'object');
expect([], 'to be an object');
expect({foo: 123}, 'to be an', 'object');
expect({foo: 123}, 'to be an object');
expect({foo: 123}, 'to be a non-empty object');
expect({}, 'to be an empty object');

@@ -312,2 +314,10 @@ expect(null, 'not to be an', 'object');

});
expect([0, 1, 2, 3, 4], 'to be an array whose items satisfy', 'to be a number');
expect([[1], [2]], 'to be an array whose items satisfy', 'to be an array whose items satisfy', 'to be a number');
expect([[], []], 'to be a non-empty array whose items satisfy', function (item) {
expect(item, 'to be an empty array');
});
```

@@ -318,3 +328,3 @@

```js
expect([[0, 1, 2], [4, '5', 6], [7, 8, '9']],
expect([[0, 1, 2], [4, '5', 6], [7, 8, '9']],
'to be an array whose items satisfy', function (arr) {

@@ -343,4 +353,8 @@ expect(arr, 'to be an array whose items satisfy', function (item) {

'to be a map whose keys satisfy', function (key) {
expect(key, 'to match', /[a-z]{3}/);
expect(key, 'to match', /^[a-z]{3}$/);
});
expect({ foo: 0, bar: 1, baz: 2, qux: 3 },
'to be a map whose keys satisfy',
'to match', /^[a-z]{3}$/);
```

@@ -371,2 +385,6 @@

});
expect({ foo: 0, bar: 1, baz: 2, qux: 3 },
'to be a map whose values satisfy',
'to be a number');
```

@@ -475,3 +493,3 @@

Heavily borrows from [expect.js](https://github.com/LearnBoost/expect.js) by
Heavily borrows from [expect.js](https://github.com/LearnBoost/expect.js) by
Guillermo Rauch - MIT.

@@ -92,6 +92,16 @@ /*global describe, it, expect*/

expect([], 'to be an array');
expect(['abc'], 'to be an array of strings');
expect([{}], 'to be an array of objects');
expect([{}], 'to be a non-empty array of objects');
expect([/foo/, /bar/], 'to be a non-empty array of regexps');
expect([[], [], []], 'to be an array of arrays');
expect(['abc'], 'to be a non-empty array of strings');
expect([], 'to be an empty array');
expect({}, 'to be an', Object);
expect({}, 'to be an empty object');
expect({foo: 123}, 'to be a non-empty object');
expect([123], 'to be a non-empty array');
expect([], 'to be an', 'object');
expect([], 'to be an object');
expect([], 'to be an empty object');
expect([], 'to be an', Array);

@@ -336,3 +346,5 @@ expect(/ab/, 'to be a', RegExp);

expect({ my: 'object' }, 'not to be empty');
expect({ my: 'object' }, 'to be non-empty');
expect([1,2,3], 'not to be empty');
expect([1,2,3], 'to be non-empty');
});

@@ -346,2 +358,6 @@

expect(function () {
expect('', 'to be non-empty');
}, 'to throw exception', "expected '' not to be empty");
expect(function () {
expect(null, 'to be empty');

@@ -577,3 +593,3 @@ }, 'to throw exception', "Assertion 'to be empty' only supports strings, arrays and objects");

describe('to be an array whose items satisfy assertion', function () {
it('only accepts a function', function () {
it('requires a function or a string as the third argument', function () {
expect(function () {

@@ -594,2 +610,8 @@ expect([1,2,3], 'to be an array whose items satisfy');

it('supports the non-empty clause', function () {
expect([1], 'to be a non-empty array whose items satisfy', function (item) {
expect(item, 'to be a number');
});
});
it('asserts that the given callback does not throw for any items in the array', function () {

@@ -603,2 +625,8 @@ expect([0,1,2,3], 'to be an array whose items satisfy', function (item) {

});
expect([0,1,2,3], 'to be an array whose items satisfy', 'to be a number');
expect(['0','1','2','3'], 'to be an array whose items satisfy', 'not to be a number');
expect([[1], [2]], 'to be an array whose items satisfy', 'to be an array whose items satisfy', 'to be a number');
});

@@ -612,2 +640,12 @@

}, 'to throw', /expected 1 not to be a 'number'/);
expect(function () {
expect(['0',1,'2','3'], 'to be an array whose items satisfy', 'not to be a number');
}, 'to throw', /expected 1 not to be a 'number'/);
expect(function () {
expect([], 'to be a non-empty array whose items satisfy', function (item) {
expect(item, 'not to be a number');
});
}, 'to throw', 'expected [] not to be empty');
});

@@ -644,3 +682,3 @@

describe('to be a map whose values satisfy assertion', function () {
it('only accepts a function', function () {
it('requires a function or a string as the third argument', function () {
expect(function () {

@@ -669,4 +707,24 @@ expect([1,2,3], 'to be a map whose values satisfy');

});
expect({ foo: 0, bar: 1, baz: 2, qux: 3 }, 'to be a map whose values satisfy', 'to be a number');
expect({ foo: '0', bar: '1', baz: '2', qux: '3' }, 'to be a map whose values satisfy', 'not to be a number');
});
it('supports the non-empty clause', function () {
expect({ foo: '0' }, 'to be a non-empty map whose values satisfy', function (value) {
expect(value, 'to equal', '0');
});
});
it('supports "hash" and "object" as aliases', function () {
expect({ foo: '0' }, 'to be an object whose values satisfy', function (value) {
expect(value, 'not to be a number');
});
expect({ foo: '0' }, 'to be a hash whose values satisfy', function (value) {
expect(value, 'not to be a number');
});
});
it('fails when the assertion fails', function () {

@@ -712,3 +770,3 @@ expect(function () {

describe('to be a map whose keys satisfy assertion', function () {
it('only accepts a function', function () {
it('requires a function or string as the third argument', function () {
expect(function () {

@@ -735,10 +793,30 @@ expect([1,2,3], 'to be a map whose keys satisfy');

expect({ foo: 0, bar: 1, baz: 2, qux: 3 }, 'to be a map whose keys satisfy', function (key) {
expect(key, 'to match', /[a-z]{3}/);
expect(key, 'to match', /^[a-z]{3}$/);
});
expect({ foo: 0, bar: 1, baz: 2, qux: 3 }, 'to be a map whose keys satisfy', 'not to be empty');
expect({ foo: 0, bar: 1, baz: 2, qux: 3 }, 'to be a map whose keys satisfy', 'to match', /^[a-z]{3}$/);
});
it('supports the non-empty clause', function () {
expect({ foo: '0' }, 'to be a non-empty map whose keys satisfy', function (key) {
expect(key, 'to match', /^[a-z]{3}$/);
});
});
it('supports "hash" and "object" as aliases', function () {
expect({ foo: '0' }, 'to be an object whose keys satisfy', function (key) {
expect(key, 'to match', /^[a-z]{3}$/);
});
expect({ foo: '0' }, 'to be a hash whose keys satisfy', function (key) {
expect(key, 'to match', /^[a-z]{3}$/);
});
});
it('fails when the assertion fails', function () {
expect(function () {
expect({ foo: 0, bar: 1, Baz: 2, qux: 3 }, 'to be a map whose keys satisfy', function (key) {
expect(key, 'to match', /[a-z]{3}/);
expect(key, 'to match', /^[a-z]{3}$/);
});

@@ -745,0 +823,0 @@ }, 'to throw', /expected 'Baz' to match/);

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc