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

unexpected

Package Overview
Dependencies
Maintainers
1
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 0.1.1 to 1.0.0

44

lib/unexpected.js

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

expect.addAssertion('to [not] be', function (value) {
expect.addAssertion('[not] to be', function (value) {
this.assert(this.obj === value);
});
expect.addAssertion('to [not] be (ok|truthy)', function () {
expect.addAssertion('[not] to be (ok|truthy)', function () {
this.assert(this.obj);
});
expect.addAssertion('to [not] be falsy', function () {
expect.addAssertion('[not] to be falsy', function () {
this.assert(!this.obj);
});
expect.addAssertion('to [not] be (a|an)', function (type) {
expect.addAssertion('[not] to be (a|an)', function (type) {
var subject = this.obj;

@@ -289,4 +289,4 @@ if ('string' === typeof type) {

// Alias for common 'to [not] be (a|an)' assertions
expect.addAssertion('to [not] be (a|an) (boolean|number|string|function|object|array|regexp|regex|regular expression)', function () {
// Alias for common '[not] to be (a|an)' assertions
expect.addAssertion('[not] to be (a|an) (boolean|number|string|function|object|array|regexp|regex|regular expression)', function () {
var matches = /(.* be (?:a|an)) ([\w\s]+)/.exec(this.testDescription);

@@ -296,7 +296,7 @@ expect(this.obj, matches[1], matches[2]);

expect.addAssertion('to [not] match', function (regexp) {
expect.addAssertion('[not] to match', function (regexp) {
this.assert(regexp.exec(this.obj));
});
expect.addAssertion('to [not] have [own] property', function (key, value) {
expect.addAssertion('[not] to have [own] property', function (key, value) {
if (this.flags.own) {

@@ -314,3 +314,3 @@ this.assert(this.obj && hasOwnProperty(this.obj, key));

expect.addAssertion('to [not] have length', function (length) {
expect.addAssertion('[not] to have length', function (length) {
if (!this.obj || typeof this.obj.length !== 'number') {

@@ -323,3 +323,3 @@ throw new Error("Assertion '" + this.testDescription +

expect.addAssertion('to [not] be empty', function () {
expect.addAssertion('[not] to be empty', function () {
var type = typeof this.obj;

@@ -338,3 +338,3 @@ if (this.obj && 'number' === typeof this.obj.length) {

expect.addAssertion('to [not] [only] have (key|keys)', function (keys) {
expect.addAssertion('to [not] [only] have (key|keys)', '[not] to have (key|keys)', function (keys) {
var obj = this.obj;

@@ -356,3 +356,3 @@

expect.addAssertion('to [not] contain', function (arg) {
expect.addAssertion('[not] to contain', function (arg) {
var args = Array.prototype.slice.call(arguments);

@@ -377,3 +377,3 @@ var that = this;

expect.addAssertion('to [not] be within', function (start, finish) {
expect.addAssertion('[not] to be within', function (start, finish) {
this.args = [start + '..' + finish];

@@ -410,7 +410,15 @@ if (typeof this.obj !== 'number') {

expect.addAssertion('to [not] equal', function (value) {
this.assert(expect.eql(value, this.obj));
expect.addAssertion('[not] to equal', function (value) {
try {
this.assert(expect.eql(value, this.obj));
} catch (e) {
if (!this.flags.not) {
e.expected = value;
e.actual = this.obj;
}
throw e;
}
});
expect.addAssertion('to [not] throw (error|exception)', function (fn) {
expect.addAssertion('[not] to throw', '[not] to throw (error|exception)', function (fn) {
if (typeof this.obj !== 'function') {

@@ -432,3 +440,3 @@ throw new Error("Assertion '" + this.testDescription +

if (not) {
expect(subject, 'to not match', fn);
expect(subject, 'not to match', fn);
} else {

@@ -439,3 +447,3 @@ expect(subject, 'to match', fn);

if (not) {
expect(subject, 'to not be', fn);
expect(subject, 'not to be', fn);
} else {

@@ -442,0 +450,0 @@ expect(subject, 'to be', fn);

{
"name": "unexpected",
"version": "0.1.1",
"version": "1.0.0",
"author": "Sune Sloth Simonsen <sune@we-knowhow.dk>",

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

@@ -11,3 +11,3 @@ # Unexpected

expect([], 'to be an', 'array');
expect(window, 'to not be an', Image);
expect(window, 'not to be an', Image);
```

@@ -81,5 +81,5 @@

expect(true, 'to be ok');
expect(true, 'to not be falsy');
expect(true, 'not to be falsy');
expect({}, 'to be truthy');
expect(0, 'to not be ok');
expect(0, 'not to be ok');
expect(0, 'to be falsy');

@@ -94,8 +94,8 @@ expect(null, 'to be falsy');

expect(obj, 'to be', obj);
expect(obj, 'to not be', {});
expect(obj, 'not to be', {});
expect(1, 'to be', 1);
expect(NaN, 'to not be', NaN);
expect(1, 'to not be', true);
expect('1', 'to not be', 1);
expect(null, 'to not be', undefined);
expect(NaN, 'not to be', NaN);
expect(1, 'not to be', true);
expect('1', 'not to be', 1);
expect(null, 'not to be', undefined);
```

@@ -108,3 +108,3 @@

expect(1, 'to equal', '1');
expect(null, 'to not equal', '1');
expect(null, 'not to equal', '1');
var now = new Date();

@@ -129,4 +129,4 @@ expect(now, 'to equal', now);

expect(null, 'to not be an', 'object');
expect(null, 'to not be an object');
expect(null, 'not to be an', 'object');
expect(null, 'not to be an object');

@@ -144,4 +144,4 @@ expect(true, 'to be a', 'boolean');

expect('test', 'to match', /.*st/);
expect('test', 'to not match', /foo/);
expect(null, 'to not match', /foo/);
expect('test', 'not to match', /foo/);
expect(null, 'not to match', /foo/);
```

@@ -154,3 +154,3 @@

expect('hello world', 'to contain', 'world');
expect(null, 'to not contain', 'world');
expect(null, 'not to contain', 'world');
```

@@ -163,3 +163,3 @@

expect([1,2,3], 'to have length', 3);
expect([1,2,3], 'to not have length', 4);
expect([1,2,3], 'not to have length', 4);
```

@@ -174,4 +174,4 @@

expect({ length: 0, duck: 'typing' }, 'to be empty');
expect({ my: 'object' }, 'to not be empty');
expect([1,2,3], 'to not be empty');
expect({ my: 'object' }, 'not to be empty');
expect([1,2,3], 'not to be empty');
```

@@ -188,3 +188,3 @@

expect({a: 'b'}, 'to have own property', 'a');
expect(Object.create({a: 'b'}), 'to not have own property', 'a');
expect(Object.create({a: 'b'}), 'not to have own property', 'a');
```

@@ -195,5 +195,5 @@

```js
expect(null, 'to not have key', 'a');
expect(null, 'not to have key', 'a');
expect({ a: 'b' }, 'to have key', 'a');
expect({ a: 'b' }, 'to not have key', 'b');
expect({ a: 'b' }, 'not to have key', 'b');
expect({ a: 'b', c: 'd' }, 'to not only have key', 'a');

@@ -205,6 +205,7 @@ expect({ a: 'b', c: 'd' }, 'to only have keys', 'a', 'c');

**throw exception** / **throw error**: asserts that the `Function` throws or not when called
**throw exception** / **throw error** / **throw**: asserts that the `Function` throws or not when called
```js
expect(fn, 'to throw exception'); // synonym of throwException
expect(fn, 'to throw exception');
expect(fn, 'to throw');
expect(fn, 'to throw exception', function (e) { // get the exception object

@@ -215,3 +216,3 @@ expect(e, 'to be a', SyntaxError);

expect(fn, 'to throw error', 'matches the exact exception message');
expect(fn2, 'to not throw error');
expect(fn2, 'not to throw error');
```

@@ -225,4 +226,4 @@

expect(4, 'to be within', 0, 4);
expect(-1, 'to not be within', 0, 4);
expect(5, 'to not be within', 0, 4);
expect(-1, 'not to be within', 0, 4);
expect(5, 'not to be within', 0, 4);
```

@@ -229,0 +230,0 @@

@@ -16,5 +16,5 @@ /*global describe, it, expect*/

expect(true, 'to be ok');
expect(true, 'to not be falsy');
expect(true, 'not to be falsy');
expect({}, 'to be truthy');
expect(0, 'to not be ok');
expect(0, 'not to be ok');
expect(0, 'to be falsy');

@@ -52,8 +52,12 @@ expect(null, 'to be falsy');

expect(obj, 'to be', obj);
expect(obj, 'to not be', {});
expect(obj, 'not to be', {});
expect(1, 'to be', 1);
expect(NaN, 'to not be', NaN);
expect(1, 'to not be', true);
expect('1', 'to not be', 1);
expect(null, 'to not be', undefined);
expect(NaN, 'not to be', NaN);
expect(1, 'not to be', true);
expect('1', 'not to be', 1);
expect(null, 'not to be', undefined);
if (typeof Buffer !== 'undefined') {
var buffer = new Buffer([0x45, 0x59]);
expect(buffer, 'to be', buffer);
}
});

@@ -67,4 +71,4 @@

expect(function () {
expect(true, 'to not be', true);
}, 'to throw exception', "expected true to not be true");
expect(true, 'not to be', true);
}, 'to throw exception', "expected true not to be true");
});

@@ -84,8 +88,8 @@ });

expect(/ab/, 'to be a regexp');
expect(123, 'to not be a regex');
expect(123, 'not to be a regex');
expect(/ab/, 'to be a regex');
expect(/ab/, 'to be a regular expression');
expect(123, 'to not be a regular expression');
expect(null, 'to not be an', 'object');
expect(null, 'to not be an object');
expect(123, 'not to be a regular expression');
expect(null, 'not to be an', 'object');
expect(null, 'not to be an object');
expect(true, 'to be a', 'boolean');

@@ -103,4 +107,4 @@ expect(true, 'to be a boolean');

expect(function () {
expect([], 'to not be an', 'array');
}, 'to throw exception', "expected [] to not be an 'array'");
expect([], 'not to be an', 'array');
}, 'to throw exception', "expected [] not to be an 'array'");
});

@@ -114,3 +118,3 @@ });

expect(1, 'to equal', 1);
expect(null, 'to not equal', '1');
expect(null, 'not to equal', '1');
var now = new Date();

@@ -121,3 +125,3 @@ expect(now, 'to equal', now);

expect(null, 'to equal', null);
expect(null, 'to not equal', undefined);
expect(null, 'not to equal', undefined);
expect(undefined, 'to equal', undefined);

@@ -127,8 +131,11 @@ expect(true, 'to equal', true);

expect({ a: { b: 'c' } }, 'to equal', { a: { b: 'c' } });
expect({ a: { b: 'c' } }, 'to not equal', { a: { b: 'd' } });
expect({ a: { b: 'c' } }, 'not to equal', { a: { b: 'd' } });
expect(/foo/, 'to equal', /foo/);
expect(/foo/i, 'to not equal', /foo/);
expect(/foo/i, 'not to equal', /foo/);
expect(/foo/gm, 'to equal', /foo/gm);
expect(/foo/m, 'to not equal', /foo/i);
expect(/foo/m, 'not to equal', /foo/i);
expect(/foo/m, 'to equal', new RegExp('foo', 'm'));
if (typeof Buffer !== 'undefined') {
expect(new Buffer([0x45, 0x59]), 'to equal', new Buffer([0x45, 0x59]));
}
});

@@ -142,5 +149,25 @@

expect(function () {
expect({ a: 'b' }, 'to not equal', { a: 'b' });
}, 'to throw exception', "expected { a: 'b' } to not equal { a: 'b' }");
expect({ a: 'b' }, 'not to equal', { a: 'b' });
}, 'to throw exception', "expected { a: 'b' } not to equal { a: 'b' }");
});
it("throws an error with 'expected' and 'actual' properties when not negated", function () {
var expected = 123,
actual = 456;
expect(function () {
expect(actual, 'to equal', expected);
}, 'to throw exception', function (e) {
expect(e.expected, 'to equal', expected);
expect(e.actual, 'to equal', actual);
});
});
it("throws an error without 'expected' and 'actual' properties when negated", function () {
expect(function () {
expect(123, 'not to equal', 123);
}, 'to throw exception', function (e) {
expect(e.expected, 'not to be ok');
expect(e.actual, 'not to be ok');
});
});
});

@@ -154,3 +181,3 @@

}, 'to throw exception');
}, 'to throw exception', 'expected [Function] to throw exception');
}, 'to throw', 'expected [Function] to throw exception');
});

@@ -178,3 +205,3 @@

throw new Error('Other error');
}, 'to not throw exception', /matches the exception message/);
}, 'not to throw exception', /matches the exception message/);
});

@@ -188,3 +215,3 @@

throw new Error('matches the exception message');
}, 'to not throw exception', 'the exception message');
}, 'not to throw exception', 'the exception message');
});

@@ -196,4 +223,4 @@ });

expect('test', 'to match', /.*st/);
expect('test', 'to not match', /foo/);
expect(null, 'to not match', /foo/);
expect('test', 'not to match', /foo/);
expect(null, 'not to match', /foo/);
});

@@ -213,3 +240,3 @@

expect('hello world', 'to contain', 'world');
expect(null, 'to not contain', 'world');
expect(null, 'not to contain', 'world');
});

@@ -240,3 +267,3 @@

expect([1,2,3], 'to have length', 3);
expect([1,2,3], 'to not have length', 4);
expect([1,2,3], 'not to have length', 4);
expect({ length: 4 }, 'to have length', 4);

@@ -267,10 +294,10 @@ });

expect({a: 'b'}, 'to have property', 'toString');
expect({a: 'b'}, 'to not have property', 'b');
expect({a: 'b'}, 'not to have property', 'b');
expect({a: 'b'}, 'to have own property', 'a');
expect(create({a: 'b'}), 'to not have own property', 'a');
expect(1, 'to not have property', 'a');
expect(null, 'to not have property', 'a');
expect(undefined, 'to not have property', 'a');
expect(true, 'to not have property', 'a');
expect(false, 'to not have property', 'a');
expect(create({a: 'b'}), 'not to have own property', 'a');
expect(1, 'not to have property', 'a');
expect(null, 'not to have property', 'a');
expect(undefined, 'not to have property', 'a');
expect(true, 'not to have property', 'a');
expect(false, 'not to have property', 'a');
});

@@ -293,9 +320,9 @@

// property expectations on value expects the property to be present
expect(null, 'to not have property', 'a', 'b');
}, 'to throw exception', "expected null to not have property 'a', 'b'");
expect(null, 'not to have property', 'a', 'b');
}, 'to throw exception', "expected null not to have property 'a', 'b'");
expect(function () {
// property expectations on value expects the property to be present
expect(null, 'to not have own property', 'a', 'b');
}, 'to throw exception', "expected null to not have own property 'a', 'b'");
expect(null, 'not to have own property', 'a', 'b');
}, 'to throw exception', "expected null not to have own property 'a', 'b'");
});

@@ -310,4 +337,4 @@ });

expect({ length: 0, duck: 'typing' }, 'to be empty');
expect({ my: 'object' }, 'to not be empty');
expect([1,2,3], 'to not be empty');
expect({ my: 'object' }, 'not to be empty');
expect([1,2,3], 'not to be empty');
});

@@ -329,3 +356,3 @@

expect({ a: 'b' }, 'to have key', 'a');
expect({ a: 'b' }, 'to not have key', 'b');
expect({ a: 'b' }, 'not to have key', 'b');
expect({ a: 'b', c: 'd' }, 'to not only have key', 'a');

@@ -335,6 +362,6 @@ expect({ a: 'b', c: 'd' }, 'to only have keys', 'a', 'c');

expect({ a: 'b', c: 'd', e: 'f' }, 'to not only have keys', ['a', 'c']);
expect(null, 'to not have key', 'a');
expect(undefined, 'to not have key', 'a');
expect(true, 'to not have key', 'a');
expect(false, 'to not have key', 'a');
expect(null, 'not to have key', 'a');
expect(undefined, 'not to have key', 'a');
expect(true, 'not to have key', 'a');
expect(false, 'not to have key', 'a');
});

@@ -352,4 +379,4 @@

expect(function () {
expect({ a: 'b', b: 'c' }, 'to not have key', 'b');
}, 'to throw exception', "expected { a: 'b', b: 'c' } to not have key 'b'");
expect({ a: 'b', b: 'c' }, 'not to have key', 'b');
}, 'to throw exception', "expected { a: 'b', b: 'c' } not to have key 'b'");

@@ -375,4 +402,4 @@ expect(function () {

expect(4, 'to be within', 0, 4);
expect(-1, 'to not be within', 0, 4);
expect(5, 'to not be within', 0, 4);
expect(-1, 'not to be within', 0, 4);
expect(5, 'not to be within', 0, 4);
});

@@ -382,7 +409,7 @@

expect(function () {
expect(4, 'to not be within', 0, 4);
}, 'to throw exception', "expected 4 to not be within '0..4'");
expect(4, 'not to be within', 0, 4);
}, 'to throw exception', "expected 4 not to be within '0..4'");
expect(function () {
expect(null, 'to not be within', 0, 4);
}, 'to throw exception', "expected null to not be within '0..4'");
expect(null, 'not to be within', 0, 4);
}, 'to throw exception', "expected null not to be within '0..4'");
});

@@ -389,0 +416,0 @@ });

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