unexpected
Advanced tools
Comparing version 2.1.8 to 3.0.0
{ | ||
"name": "unexpected", | ||
"version": "2.1.8", | ||
"version": "3.0.0", | ||
"author": "Sune Sloth Simonsen <sune@we-knowhow.dk>", | ||
@@ -17,5 +17,6 @@ "keywords": [ | ||
"scripts": { | ||
"test": "make test" | ||
"test": "make test", | ||
"travis": "make test && make test-phantomjs" | ||
}, | ||
"main": "./lib/unexpected.js", | ||
"main": "./lib/index.js", | ||
"dependencies": {}, | ||
@@ -22,0 +23,0 @@ "devDependencies": { |
@@ -0,3 +1,4 @@ | ||
/*global process, expect:true*/ | ||
expect = process.env.COVERAGE ? | ||
require('../lib-cov/unexpected') : | ||
require('../lib/unexpected'); | ||
require('../lib-cov/') : | ||
require('../lib/'); |
@@ -1,2 +0,2 @@ | ||
/*global describe, it, expect*/ | ||
/*global describe, it, expect, beforeEach, setTimeout*/ | ||
@@ -11,2 +11,10 @@ // use this instead of Object.create in order to make the tests run in | ||
function itSkipInPhantom() { //... | ||
if (typeof mochaPhantomJS === 'undefined') { | ||
it.apply(it, arguments); | ||
} else { | ||
it.skip.apply(it, arguments); | ||
} | ||
} | ||
describe('unexpected', function () { | ||
@@ -60,3 +68,3 @@ describe('argument validation', function () { | ||
expect(new Error('error message'), 'to be a number'); | ||
}, 'to throw', "expected [Error: error message] to be a 'number'"); | ||
}, 'to throw', "expected [Error: error message] to be a number"); | ||
}); | ||
@@ -350,4 +358,4 @@ | ||
expect([], 'to have length', 0); | ||
expect([1,2,3], 'to have length', 3); | ||
expect([1,2,3], 'not to have length', 4); | ||
expect([1, 2, 3], 'to have length', 3); | ||
expect([1, 2, 3], 'not to have length', 4); | ||
expect({ length: 4 }, 'to have length', 4); | ||
@@ -402,3 +410,3 @@ }); | ||
expect(function () { | ||
// property expectations on value expects the property to be present | ||
// property expectations ignores value if property | ||
expect(null, 'not to have property', 'a', 'b'); | ||
@@ -503,4 +511,4 @@ }, 'to throw exception', "expected null not to have property 'a', 'b'"); | ||
expect({ my: 'object' }, 'to be non-empty'); | ||
expect([1,2,3], 'not to be empty'); | ||
expect([1,2,3], 'to be non-empty'); | ||
expect([1, 2, 3], 'not to be empty'); | ||
expect([1, 2, 3], 'to be non-empty'); | ||
}); | ||
@@ -510,3 +518,3 @@ | ||
expect(function () { | ||
expect([1,2,3], 'to be empty'); | ||
expect([1, 2, 3], 'to be empty'); | ||
}, 'to throw exception', "expected [ 1, 2, 3 ] to be empty"); | ||
@@ -516,3 +524,3 @@ | ||
expect('', 'to be non-empty'); | ||
}, 'to throw exception', "expected '' not to be empty"); | ||
}, 'to throw exception', "expected '' to be non-empty"); | ||
@@ -753,7 +761,7 @@ expect(function () { | ||
expect(function () { | ||
expect([1,2,3], 'to be an array whose items satisfy'); | ||
expect([1, 2, 3], 'to be an array whose items satisfy'); | ||
}, 'to throw', 'Assertions "to be an array whose items satisfy" expects a functions as argument'); | ||
expect(function () { | ||
expect([1,2,3], 'to be an array whose items satisfy', 42); | ||
expect([1, 2, 3], 'to be an array whose items satisfy', 42); | ||
}, 'to throw', 'Assertions "to be an array whose items satisfy" expects a functions as argument'); | ||
@@ -765,3 +773,3 @@ }); | ||
expect(42, 'to be an array whose items satisfy', function (item) {}); | ||
}, 'to throw', "expected 42 to be an 'array'"); | ||
}, 'to throw', /expected 42 to be an array/); | ||
}); | ||
@@ -776,3 +784,3 @@ | ||
it('asserts that the given callback does not throw for any items in the array', function () { | ||
expect([0,1,2,3], 'to be an array whose items satisfy', function (item, index) { | ||
expect([0, 1, 2, 3], 'to be an array whose items satisfy', function (item, index) { | ||
expect(item, 'to be a number'); | ||
@@ -782,3 +790,3 @@ expect(index, 'to be a number'); | ||
expect(['0','1','2','3'], 'to be an array whose items satisfy', function (item, index) { | ||
expect(['0', '1', '2', '3'], 'to be an array whose items satisfy', function (item, index) { | ||
expect(item, 'not to be a number'); | ||
@@ -788,5 +796,5 @@ expect(index, 'to be a number'); | ||
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', 'to be a number'); | ||
expect(['0','1','2','3'], 'to be an array whose items satisfy', 'not to be a number'); | ||
expect(['0', '1', '2', '3'], 'to be an array whose items satisfy', 'not to be a number'); | ||
@@ -797,3 +805,3 @@ expect([[1], [2]], 'to be an array whose items satisfy', 'to be an array whose items satisfy', 'to be a number'); | ||
it('provides the item index to the callback function', function () { | ||
var arr = ['0','1','2','3']; | ||
var arr = ['0', '1', '2', '3']; | ||
expect(arr, 'to be an array whose items satisfy', function (item, index) { | ||
@@ -807,10 +815,10 @@ expect(index, 'to be a number'); | ||
expect(function () { | ||
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', function (item) { | ||
expect(item, 'not to be a number'); | ||
}); | ||
}, 'to throw', /expected 1 not to be a 'number'/); | ||
}, '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(['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/); | ||
@@ -821,3 +829,3 @@ expect(function () { | ||
}); | ||
}, 'to throw', 'expected [] not to be empty'); | ||
}, 'to throw', /expected \[\] to be non-empty/); | ||
}); | ||
@@ -833,3 +841,3 @@ | ||
"failed expectation in [ 0, 1, '2', 3, 4 ]:\n" + | ||
" 2: expected '2' to be a 'number'\n" + | ||
" 2: expected '2' to be a number\n" + | ||
" 4: expected 4 to be less than 4"); | ||
@@ -848,5 +856,5 @@ }); | ||
" 1: failed expectation in [ 4, '5', 6 ]:\n" + | ||
" 1: expected '5' to be a 'number'\n" + | ||
" 1: expected '5' to be a number\n" + | ||
" 2: failed expectation in [ 7, 8, '9' ]:\n" + | ||
" 2: expected '9' to be a 'number'"); | ||
" 2: expected '9' to be a number"); | ||
}); | ||
@@ -858,7 +866,7 @@ }); | ||
expect(function () { | ||
expect([1,2,3], 'to be a map whose values satisfy'); | ||
expect([1, 2, 3], 'to be a map whose values satisfy'); | ||
}, 'to throw', 'Assertions "to be a map whose values satisfy" expects a functions as argument'); | ||
expect(function () { | ||
expect([1,2,3], 'to be a map whose values satisfy', 42); | ||
expect([1, 2, 3], 'to be a map whose values satisfy', 42); | ||
}, 'to throw', 'Assertions "to be a map whose values satisfy" expects a functions as argument'); | ||
@@ -870,3 +878,3 @@ }); | ||
expect(42, 'to be a map whose values satisfy', function (value) {}); | ||
}, 'to throw', "expected 42 to be an 'object'"); | ||
}, 'to throw', /expected 42 to be an object/); | ||
}); | ||
@@ -909,3 +917,3 @@ | ||
}); | ||
}, 'to throw', /expected 1 not to be a 'number'/); | ||
}, 'to throw', /expected 1 not to be a number/); | ||
}); | ||
@@ -921,3 +929,3 @@ | ||
"failed expectation in { foo: 0, bar: 1, baz: '2', qux: 3, quux: 4 }:\n" + | ||
" baz: expected '2' to be a 'number'\n" + | ||
" baz: expected '2' to be a number\n" + | ||
" quux: expected 4 to be less than 4"); | ||
@@ -939,5 +947,5 @@ }); | ||
" bar: failed expectation in [ 4, '5', 6 ]:\n" + | ||
" 1: expected '5' to be a 'number'\n" + | ||
" 1: expected '5' to be a number\n" + | ||
" baz: failed expectation in [ 7, 8, '9' ]:\n" + | ||
" 2: expected '9' to be a 'number'"); | ||
" 2: expected '9' to be a number"); | ||
}); | ||
@@ -949,7 +957,7 @@ }); | ||
expect(function () { | ||
expect([1,2,3], 'to be a map whose keys satisfy'); | ||
expect([1, 2, 3], 'to be a map whose keys satisfy'); | ||
}, 'to throw', 'Assertions "to be a map whose keys satisfy" expects a functions as argument'); | ||
expect(function () { | ||
expect([1,2,3], 'to be a map whose keys satisfy', 42); | ||
expect([1, 2, 3], 'to be a map whose keys satisfy', 42); | ||
}, 'to throw', 'Assertions "to be a map whose keys satisfy" expects a functions as argument'); | ||
@@ -961,3 +969,3 @@ }); | ||
expect(42, 'to be a map whose keys satisfy', function (key) {}); | ||
}, 'to throw', "expected 42 to be an 'object'"); | ||
}, 'to throw', /expected 42 to be an object/); | ||
}); | ||
@@ -1020,12 +1028,2 @@ | ||
function sortBy(arr, property) { | ||
arr.sort(function (x, y) { | ||
var xp = x[property]; | ||
var yp = y[property]; | ||
if (xp > yp) { return 1; } | ||
if (xp < yp) { return -1; } | ||
return 0; | ||
}); | ||
} | ||
describe('addAssertion', function () { | ||
@@ -1041,2 +1039,16 @@ it('is chainable', function () { | ||
it('supports transfering flags from the custom assertion to nested expect', function () { | ||
var clonedExpect = expect.clone() | ||
.addAssertion('[not] to be sorted', function (expect, subject) { | ||
expect(subject, 'to be an array'); | ||
expect(subject, '[not] to equal', [].concat(subject).sort()); | ||
}); | ||
clonedExpect([1, 2, 3], 'to be sorted'); | ||
clonedExpect([1, 3, 2], 'not to be sorted'); | ||
expect(function () { | ||
clonedExpect([1, 2, 3], 'not to be sorted'); | ||
}, 'to throw', 'expected [ 1, 2, 3 ] not to be sorted'); | ||
}); | ||
describe('pattern', function () { | ||
@@ -1167,2 +1179,104 @@ it("must be a string", function () { | ||
}); | ||
describe('error modes', function () { | ||
var errorMode = 'default'; | ||
var clonedExpect; | ||
describe('for synchronous custom assertions', function () { | ||
beforeEach(function () { | ||
clonedExpect = expect.clone() | ||
.addAssertion('[not] to be sorted', function (expect, subject) { | ||
this.errorMode = errorMode; | ||
expect(subject, 'to be an array'); | ||
expect(subject, '[not] to equal', [].concat(subject).sort()); | ||
}); | ||
}); | ||
it('errorMode=nested nest the error message of expect failures in the assertion under the assertion standard message', function () { | ||
errorMode = 'nested'; | ||
expect(function () { | ||
clonedExpect(42, 'to be sorted'); | ||
}, 'to throw', 'expected 42 to be sorted\n expected 42 to be an array'); | ||
}); | ||
it('errorMode=bubble bubbles uses the error message of expect failures in the assertion', function () { | ||
errorMode = 'bubble'; | ||
expect(function () { | ||
clonedExpect(42, 'to be sorted'); | ||
}, 'to throw', 'expected 42 to be an array'); | ||
}); | ||
it('errorMode=default uses the standard error message of the assertion', function () { | ||
errorMode = 'default'; | ||
expect(function () { | ||
clonedExpect(42, 'to be sorted'); | ||
}, 'to throw', 'expected 42 to be sorted'); | ||
}); | ||
}); | ||
describe('for asynchronous custom assertions', function () { | ||
beforeEach(function () { | ||
clonedExpect = expect.clone() | ||
.addAssertion('to be sorted after delay', function (expect, subject, delay, done) { | ||
this.errorMode = errorMode; | ||
setTimeout(function () { | ||
try { | ||
expect(subject, 'to be an array'); | ||
expect(subject, 'to equal', [].concat(subject).sort()); | ||
} catch (e) { | ||
done(e); | ||
} | ||
}, delay); | ||
}); | ||
}); | ||
it('errorMode=nested nest the error message of expect failures in the assertion under the assertion standard message', function (done) { | ||
errorMode = 'nested'; | ||
clonedExpect(42, 'to be sorted after delay', 1, function (err) { | ||
expect(err.message, 'to match', /^expected 42 to be sorted after delay 1.*\n expected 42 to be an array/); | ||
done(); | ||
}); | ||
}); | ||
it('errorMode=bubble bubbles uses the error message of expect failures in the assertion', function (done) { | ||
errorMode = 'bubble'; | ||
clonedExpect(42, 'to be sorted after delay', 1, function (err) { | ||
expect(err.message, 'to match', /^expected 42 to be an array/); | ||
done(); | ||
}); | ||
}); | ||
it('errorMode=default uses the standard error message of the assertion', function (done) { | ||
errorMode = 'default'; | ||
clonedExpect(42, 'to be sorted after delay', 1, function (err) { | ||
expect(err.message, 'to match', /^expected 42 to be sorted after delay 1/); | ||
done(); | ||
}); | ||
}); | ||
}); | ||
}); | ||
// I can't figure out why this doesn't work in mocha-phantomjs: | ||
itSkipInPhantom('truncates the stack when a custom assertion throws a regular assertion error', function () { | ||
var clonedExpect = expect.clone().addAssertion('to equal foo', function theCustomAssertion(expect, subject) { | ||
expect(subject, 'to equal', 'foo'); | ||
}); | ||
expect(function () { | ||
clonedExpect('bar', 'to equal foo'); | ||
}, 'to throw', function (err) { | ||
expect(err.stack, 'not to contain', 'theCustomAssertion'); | ||
}); | ||
}); | ||
it('does not truncate the stack when the assertion function itself contains an error', function () { | ||
var clonedExpect = expect.clone().addAssertion('to equal foo', function theCustomAssertion(expect, subject) { | ||
expect(subject, 'to equal', 'foo'); | ||
this(); // Will throw a TypeError | ||
}); | ||
expect(function () { | ||
clonedExpect('foo', 'to equal foo'); | ||
}, 'to throw', function (err) { | ||
expect(err.stack, 'to contain', 'theCustomAssertion'); | ||
}); | ||
}); | ||
}); | ||
@@ -1174,4 +1288,4 @@ | ||
clonedExpect = expect.clone(); | ||
clonedExpect.addAssertion('[not] to be answer to the Ultimate Question of Life, the Universe, and Everything', function () { | ||
this.assert(this.obj === 42); | ||
clonedExpect.addAssertion('[not] to be answer to the Ultimate Question of Life, the Universe, and Everything', function (expect, subject) { | ||
this.assert(subject === 42); | ||
}); | ||
@@ -1226,3 +1340,3 @@ }); | ||
describe('installPlugin', function () { | ||
it('calls the given plugin with the expect instance as the paramenter', function (done) { | ||
it('calls the given plugin with the expect instance as the parameter', function (done) { | ||
var plugin = function (expectInstance) { | ||
@@ -1229,0 +1343,0 @@ expect(expectInstance, 'to be', expect); |
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
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
Major refactor
Supply chain riskPackage has recently undergone a major refactor. It may be unstable or indicate significant internal changes. Use caution when updating to versions that include significant changes.
Found 1 instance in 1 package
Debug access
Supply chain riskUses debug, reflection and dynamic code execution features.
Found 1 instance in 1 package
Filesystem access
Supply chain riskAccesses the file system, and could potentially read sensitive data.
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
277081
26
5352
630
4
1