New Case Study:See how Anthropic automated 95% of dependency reviews with Socket.Learn More
Socket
Sign inDemoInstall
Socket

code

Package Overview
Dependencies
Maintainers
2
Versions
30
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

code - npm Package Compare versions

Comparing version 1.5.0 to 2.0.0

229

lib/index.js

@@ -0,5 +1,7 @@

'use strict';
// Load modules
var NodeUtil = require('util');
var Hoek = require('hoek');
const NodeUtil = require('util');
const Hoek = require('hoek');

@@ -9,3 +11,3 @@

var internals = {
const internals = {
flags: ['deep', 'not', 'once', 'only', 'part'],

@@ -19,3 +21,3 @@ grammar: ['a', 'an', 'and', 'at', 'be', 'have', 'in', 'to'],

exports.settings = {
truncateMessages: true,
truncateMessages: false,
comparePrototypes: true

@@ -27,4 +29,4 @@ };

var at = internals.at();
var location = at.filename + ':' + at.line + '.' + at.column;
const at = internals.at();
const location = at.filename + ':' + at.line + '.' + at.column;
internals.locations[location] = true;

@@ -38,3 +40,3 @@ ++internals.count;

var locations = Object.keys(internals.locations);
const locations = Object.keys(internals.locations);
return locations.length ? locations : null;

@@ -78,4 +80,4 @@ };

var original = this._ref;
original.at = internals.at(error);
const original = this._ref;
original.at = internals.at(this._ref);

@@ -85,3 +87,3 @@ throw original;

var message = (this._prefix ? this._prefix + ': ' : '') + 'Expected ' + internals.display(this._ref) + ' to ' + (this._flags.not ? 'not ' + verb : verb);
let message = (this._prefix ? this._prefix + ': ' : '') + 'Expected ' + internals.display(this._ref) + ' to ' + (this._flags.not ? 'not ' + verb : verb);
if (arguments.length === 3) { // 'actual' without 'expected'

@@ -91,3 +93,3 @@ message += ' but got ' + internals.display(actual);

var error = new Error(message);
const error = new Error(message);
Error.captureStackTrace(error, this.assert);

@@ -101,149 +103,188 @@ error.actual = actual;

[].concat(internals.flags, internals.grammar).forEach(function (word) {
internals.flags.forEach((word) => {
/* eslint-disable hapi/hapi-scope-start */
var method = internals.flags.indexOf(word) !== -1 ? function () { this._flags[word] = !this._flags[word]; return this; }
: function () { return this; };
/* eslint-enable hapi/hapi-scope-start */
Object.defineProperty(internals.Assertion.prototype, word, { get: method, configurable: true });
Object.defineProperty(internals.Assertion.prototype, word, {
get: function () {
this._flags[word] = !this._flags[word];
return this;
},
configurable: true
});
});
internals.grammar.forEach((word) => {
Object.defineProperty(internals.Assertion.prototype, word, {
get: function () {
return this;
},
configurable: true
});
});
internals.addMethod = function (names, fn) {
names = [].concat(names);
names.forEach(function (name) {
const method = function (name) {
internals.Assertion.prototype[name] = fn;
});
};
names = [].concat(names);
names.forEach(method);
};
['arguments', 'array', 'boolean', 'buffer', 'date', 'function', 'number', 'regexp', 'string', 'object'].forEach(function (word) {
['arguments', 'array', 'boolean', 'buffer', 'date', 'function', 'number', 'regexp', 'string', 'object'].forEach((word) => {
var article = ['a', 'e', 'i', 'o', 'u'].indexOf(word[0]) !== -1 ? 'an ' : 'a ';
internals.addMethod(word, function () {
const article = ['a', 'e', 'i', 'o', 'u'].indexOf(word[0]) !== -1 ? 'an ' : 'a ';
const method = function () {
var type = internals.type(this._ref);
const type = internals.type(this._ref);
return this.assert(type === word, 'be ' + article + word, type);
});
};
internals.addMethod(word, method);
});
[true, false, null, undefined].forEach(function (value) {
[true, false, null, undefined].forEach((value) => {
var name = NodeUtil.inspect(value);
internals.addMethod(name, function () {
const name = NodeUtil.inspect(value);
const method = function () {
return this.assert(this._ref === value, 'be ' + name);
});
};
internals.addMethod(name, method);
});
internals.addMethod(['include', 'includes', 'contain', 'contains'], function (value) {
internals.include = function (value) {
return this.assert(Hoek.contain(this._ref, value, this._flags), 'include ' + internals.display(value));
});
};
internals.addMethod(['include', 'includes', 'contain', 'contains'], internals.include);
internals.addMethod(['endWith', 'endsWith'], function (value) {
internals.endWith = function (value) {
internals.assert(this, typeof this._ref === 'string' && typeof value === 'string', 'Can only assert endsWith on a string, with a string');
var comparator = this._ref.slice(-value.length);
const comparator = this._ref.slice(-value.length);
return this.assert(comparator === value, 'endWith ' + internals.display(value));
});
};
internals.addMethod(['endWith', 'endsWith'], internals.endWith);
internals.addMethod(['startWith', 'startsWith'], function (value) {
internals.startWith = function (value) {
internals.assert(this, typeof this._ref === 'string' && typeof value === 'string', 'Can only assert startsWith on a string, with a string');
var comparator = this._ref.slice(0, value.length);
const comparator = this._ref.slice(0, value.length);
return this.assert(comparator === value, 'startWith ' + internals.display(value));
});
};
internals.addMethod(['startWith', 'startsWith'], internals.startWith);
internals.addMethod(['exist', 'exists'], function () {
internals.exist = function () {
return this.assert(this._ref !== null && this._ref !== undefined, 'exist');
});
};
internals.addMethod(['exist', 'exists'], internals.exist);
internals.addMethod('empty', function () {
internals.empty = function () {
internals.assert(this, typeof this._ref === 'object' || typeof this._ref === 'string', 'Can only assert empty on object, array or string');
var length = this._ref.length !== undefined ? this._ref.length : Object.keys(this._ref).length;
const length = this._ref.length !== undefined ? this._ref.length : Object.keys(this._ref).length;
return this.assert(!length, 'be empty');
});
};
internals.addMethod('empty', internals.empty);
internals.addMethod('length', function (size) {
internals.length = function (size) {
internals.assert(this, typeof this._ref === 'object' || typeof this._ref === 'string', 'Can only assert empty on object, array or string');
var length = this._ref.length !== undefined ? this._ref.length : Object.keys(this._ref).length;
const length = this._ref.length !== undefined ? this._ref.length : Object.keys(this._ref).length;
return this.assert(length === size, 'have a length of ' + size, length);
});
};
internals.addMethod('length', internals.length);
internals.addMethod(['equal', 'equals'], function (value, options) {
internals.equal = function (value, options) {
options = options || {};
var settings = Hoek.applyToDefaults({ prototype: exports.settings.comparePrototypes }, options);
var deepCompare = function (a, b) {
const settings = Hoek.applyToDefaults({ prototype: exports.settings.comparePrototypes }, options);
return Hoek.deepEqual(a, b, settings);
};
const compare = this._flags.deep ? (a, b) => Hoek.deepEqual(a, b, settings)
: (a, b) => a === b;
var shallowCompare = function (a, b) {
return this.assert(compare(this._ref, value), 'equal specified value', this._ref, value);
};
return a === b;
};
internals.addMethod(['equal', 'equals'], internals.equal);
var compare = this._flags.deep ? deepCompare : shallowCompare;
return this.assert(compare(this._ref, value), 'equal specified value', this._ref, value);
});
internals.above = function (value) {
return this.assert(this._ref > value, 'be above ' + value);
};
internals.addMethod(['above', 'greaterThan'], function (value) {
internals.addMethod(['above', 'greaterThan'], internals.above);
return this.assert(this._ref > value, 'be above ' + value);
});
internals.least = function (value) {
internals.addMethod(['least', 'min'], function (value) {
return this.assert(this._ref >= value, 'be at least ' + value);
});
};
internals.addMethod(['least', 'min'], internals.least);
internals.addMethod(['below', 'lessThan'], function (value) {
internals.below = function (value) {
return this.assert(this._ref < value, 'be below ' + value);
});
};
internals.addMethod(['below', 'lessThan'], internals.below);
internals.addMethod(['most', 'max'], function (value) {
internals.most = function (value) {
return this.assert(this._ref <= value, 'be at most ' + value);
});
};
internals.addMethod(['most', 'max'], internals.most);
internals.addMethod(['within', 'range'], function (from, to) {
internals.within = function (from, to) {
return this.assert(this._ref >= from && this._ref <= to, 'be within ' + from + '..' + to);
});
};
internals.addMethod(['within', 'range'], internals.within);
internals.addMethod('between', function (from, to) {
internals.between = function (from, to) {
return this.assert(this._ref > from && this._ref < to, 'be between ' + from + '..' + to);
});
};
internals.addMethod('between', internals.between);
internals.addMethod('about', function (value, delta) {
internals.above = function (value, delta) {
internals.assert(this, internals.type(this._ref) === 'number', 'Can only assert about on numbers');

@@ -253,33 +294,41 @@ internals.assert(this, internals.type(value) === 'number' && internals.type(delta) === 'number', 'About assertion requires two number arguments');

return this.assert(Math.abs(this._ref - value) <= delta, 'be about ' + value + ' \u00b1' + delta);
});
};
internals.addMethod('about', internals.above);
internals.addMethod(['instanceof', 'instanceOf'], function (type) {
internals.instanceof = function (type) {
return this.assert(this._ref instanceof type, 'be an instance of ' + (type.name || 'provided type'));
});
};
internals.addMethod(['instanceof', 'instanceOf'], internals.instanceof);
internals.addMethod(['match', 'matches'], function (regex) {
internals.match = function (regex) {
return this.assert(regex.exec(this._ref), 'match ' + regex);
});
};
internals.addMethod(['match', 'matches'], internals.match);
internals.addMethod(['satisfy', 'satisfies'], function (validator) {
internals.satisfy = function (validator) {
return this.assert(validator(this._ref), 'satisfy rule');
});
};
internals.addMethod(['satisfy', 'satisfies'], internals.satisfy);
internals.addMethod(['throw', 'throws'], function (/* type, message */) {
internals.throw = function (/* type, message */) {
internals.assert(this, typeof this._ref === 'function', 'Can only assert throw on functions');
internals.assert(this, !this._flags.not || !arguments.length, 'Cannot specify arguments when expecting not to throw');
var type = arguments.length && typeof arguments[0] !== 'string' && !(arguments[0] instanceof RegExp) ? arguments[0] : null;
var lastArg = arguments[1] || arguments[0];
var message = typeof lastArg === 'string' || lastArg instanceof RegExp ? lastArg : null;
const type = arguments.length && typeof arguments[0] !== 'string' && !(arguments[0] instanceof RegExp) ? arguments[0] : null;
const lastArg = arguments[1] || arguments[0];
const message = typeof lastArg === 'string' || lastArg instanceof RegExp ? lastArg : null;
var thrown = false;
let thrown = false;

@@ -297,3 +346,3 @@ try {

if (message !== null) {
var error = err.message || '';
const error = err.message || '';
this.assert(typeof message === 'string' ? error === message : error.match(message), 'throw an error with specified message', error, message);

@@ -306,8 +355,10 @@ }

return this.assert(thrown, 'throw an error');
});
};
internals.addMethod(['throw', 'throws'], internals.throw);
internals.display = function (value) {
var string = NodeUtil.inspect(value);
const string = NodeUtil.inspect(value);

@@ -323,3 +374,3 @@ if (!exports.settings.truncateMessages || string.length <= 40) {

if (typeof value === 'object') {
var keys = Object.keys(value);
const keys = Object.keys(value);
return '{ Object (' + (keys.length > 2 ? (keys.splice(0, 2).join(', ') + ', ...') : keys.join(', ')) + ') }';

@@ -357,3 +408,3 @@ }

var name = Object.prototype.toString.call(value);
const name = Object.prototype.toString.call(value);
if (internals.natives[name]) {

@@ -374,3 +425,3 @@ return internals.natives[name];

error = error || new Error();
var at = error.stack.replace(error.toString(), '').split('\n').slice(1).filter(internals.filterLocal)[0].match(/^\s*at \(?(.+)\:(\d+)\:(\d+)\)?$/);
const at = error.stack.replace(error.toString(), '').split('\n').slice(1).filter(internals.filterLocal)[0].match(/^\s*at \(?(.+)\:(\d+)\:(\d+)\)?$/);
return {

@@ -377,0 +428,0 @@ filename: at[1],

{
"name": "code",
"description": "assertion library",
"version": "1.5.0",
"repository": "git://github.com/hapijs/code",
"main": "lib/index.js",
"keywords": [
"test",
"expect",
"assertion"
],
"engines": {
"node": ">=0.10.32"
},
"dependencies": {
"hoek": "2.x.x"
},
"devDependencies": {
"lab": "5.x.x"
},
"scripts": {
"test": "lab -v -t 100 -L",
"test-cov-html": "lab -L -r html -o coverage.html"
},
"license": "BSD-3-Clause"
"name": "code",
"description": "assertion library",
"version": "2.0.0",
"repository": "git://github.com/hapijs/code",
"main": "lib/index.js",
"keywords": [
"test",
"expect",
"assertion"
],
"engines": {
"node": ">=4.0.0"
},
"dependencies": {
"hoek": "2.x.x"
},
"devDependencies": {
"lab": "7.x.x"
},
"scripts": {
"test": "lab -v -t 100 -L",
"test-cov-html": "lab -L -r html -o coverage.html"
},
"license": "BSD-3-Clause"
}

@@ -36,7 +36,7 @@ #code

- [`startWith(value)`](#startwithvalue)
- [`endWith(value)`](#startwithvalue)
- [`endWith(value)`](#endwithvalue)
- [`exist()`](#exist)
- [`empty()`](#empty)
- [`length(size)`](#lengthsize)
- [`equal(value)`](#equalvalue)
- [`equal(value[, options])`](#equalvalue-options)
- [`above(value)`](#abovevalue)

@@ -47,2 +47,3 @@ - [`least(value)`](#leastvalue)

- [`within(from, to)`](#withinfrom-to)
- [`between(from, to)`](#betweenfrom-to)
- [`about(value, delta)`](#aboutvalue-delta)

@@ -49,0 +50,0 @@ - [`instanceof(type)`](#instanceoftype)

@@ -0,6 +1,8 @@

'use strict';
// Load modules
var Code = require('..');
var Hoek = require('hoek');
var Lab = require('lab');
const Code = require('..');
const Hoek = require('hoek');
const Lab = require('lab');

@@ -10,3 +12,3 @@

var internals = {};
const internals = {};

@@ -16,10 +18,10 @@

var lab = exports.lab = Lab.script();
var describe = lab.describe;
var it = lab.it;
const lab = exports.lab = Lab.script();
const describe = lab.describe;
const it = lab.it;
describe('count()', function () {
describe('count()', () => {
it('returns assertion count', function (done) {
it('returns assertion count', (done) => {

@@ -33,7 +35,7 @@ Code.expect(10).to.be.above(5);

describe('expect()', function () {
describe('expect()', () => {
it('validates assertion', function (done) {
it('validates assertion', (done) => {
var exception = false;
let exception = false;
try {

@@ -50,5 +52,5 @@ Code.expect('abcd').to.contain('a');

it('uses grammar', function (done) {
it('uses grammar', (done) => {
var exception = false;
let exception = false;
try {

@@ -71,5 +73,5 @@ Code.expect(10).to.be.above(5);

it('asserts on invalid condition', function (done) {
it('asserts on invalid condition', (done) => {
var exception = false;
let exception = false;
try {

@@ -86,5 +88,5 @@ Code.expect('abcd').to.contain('e');

it('asserts on invalid condition (not)', function (done) {
it('asserts on invalid condition (not)', (done) => {
var exception = false;
let exception = false;
try {

@@ -101,5 +103,5 @@ Code.expect('abcd').to.not.contain('a');

it('asserts on invalid condition (with actual)', function (done) {
it('asserts on invalid condition (with actual)', (done) => {
var exception = false;
let exception = false;
try {

@@ -116,5 +118,5 @@ Code.expect('abcd').to.have.length(3);

it('asserts on invalid condition (prefix)', function (done) {
it('asserts on invalid condition (prefix)', (done) => {
var exception = false;
let exception = false;
try {

@@ -131,6 +133,8 @@ Code.expect('abcd', 'Oops').to.contain('e');

it('asserts on invalid condition (large array, display truncated)', function (done) {
it('asserts on invalid condition (large array, display truncated)', (done) => {
var exception = false;
let exception = false;
const origTruncate = Code.settings.truncateMessages;
try {
Code.settings.truncateMessages = true;
Code.expect([1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18]).to.be.a.string();

@@ -142,2 +146,3 @@ }

Code.settings.truncateMessages = origTruncate;
Hoek.assert(exception.message === 'Expected [Array(18)] to be a string but got \'array\'', exception);

@@ -147,6 +152,6 @@ done();

it('asserts on invalid condition (large array, display not truncated)', function (done) {
it('asserts on invalid condition (large array, display not truncated)', (done) => {
var exception = false;
var origTruncate = Code.settings.truncateMessages;
let exception = false;
const origTruncate = Code.settings.truncateMessages;
try {

@@ -165,6 +170,8 @@ Code.settings.truncateMessages = false;

it('asserts on invalid condition (large object, display truncated)', function (done) {
it('asserts on invalid condition (large object, display truncated)', (done) => {
var exception = false;
let exception = false;
const origTruncate = Code.settings.truncateMessages;
try {
Code.settings.truncateMessages = true;
Code.expect({ a: 1, b: 2, c: 3, d: 4, e: 5, f: 6, g: 7, h: 8, i: 9, j: 10 }).to.be.a.string();

@@ -176,2 +183,3 @@ }

Code.settings.truncateMessages = origTruncate;
Hoek.assert(exception.message === 'Expected { Object (a, b, ...) } to be a string but got \'object\'', exception);

@@ -181,6 +189,6 @@ done();

it('asserts on invalid condition (large object, display not truncated)', function (done) {
it('asserts on invalid condition (large object, display not truncated)', (done) => {
var exception = false;
var origTruncate = Code.settings.truncateMessages;
let exception = false;
const origTruncate = Code.settings.truncateMessages;
try {

@@ -199,6 +207,6 @@ Code.settings.truncateMessages = false;

it('handles multi-line error message', function (done) {
it('handles multi-line error message', (done) => {
var exception = false;
var origTruncate = Code.settings.truncateMessages;
let exception = false;
const origTruncate = Code.settings.truncateMessages;
try {

@@ -217,6 +225,8 @@ Code.settings.truncateMessages = false;

it('asserts on invalid condition (long object values, display truncated)', function (done) {
it('asserts on invalid condition (long object values, display truncated)', (done) => {
var exception = false;
let exception = false;
const origTruncate = Code.settings.truncateMessages;
try {
Code.settings.truncateMessages = true;
Code.expect({ a: 12345678901234567890, b: 12345678901234567890 }).to.be.a.string();

@@ -228,2 +238,3 @@ }

Code.settings.truncateMessages = origTruncate;
Hoek.assert(exception.message === 'Expected { Object (a, b) } to be a string but got \'object\'', exception);

@@ -233,6 +244,6 @@ done();

it('asserts on invalid condition (long object values, display not truncated)', function (done) {
it('asserts on invalid condition (long object values, display not truncated)', (done) => {
var exception = false;
var origTruncate = Code.settings.truncateMessages;
let exception = false;
const origTruncate = Code.settings.truncateMessages;
try {

@@ -251,6 +262,8 @@ Code.settings.truncateMessages = false;

it('asserts on invalid condition (long string, display truncated)', function (done) {
it('asserts on invalid condition (long string, display truncated)', (done) => {
var exception = false;
let exception = false;
const origTruncate = Code.settings.truncateMessages;
try {
Code.settings.truncateMessages = true;
Code.expect('{ a: 1, b: 2, c: 3, d: 4, e: 5, f: 6, g: 7, h: 8, i: 9, j: 10 }').to.be.a.number();

@@ -262,2 +275,3 @@ }

Code.settings.truncateMessages = origTruncate;
Hoek.assert(exception.message === 'Expected \'{ a: 1, b: 2, c: 3, d: 4, e: 5, f: 6, g...\' to be a number but got \'string\'', exception);

@@ -267,6 +281,6 @@ done();

it('asserts on invalid condition (long string, display not truncated)', function (done) {
it('asserts on invalid condition (long string, display not truncated)', (done) => {
var exception = false;
var origTruncate = Code.settings.truncateMessages;
let exception = false;
const origTruncate = Code.settings.truncateMessages;
try {

@@ -285,5 +299,5 @@ Code.settings.truncateMessages = false;

it('resets flags between chained assertions', function (done) {
it('resets flags between chained assertions', (done) => {
var exception = false;
let exception = false;
try {

@@ -295,3 +309,3 @@

Code.expect('abc').to.contain('a').and.to.not.contain('d').and.to.contain('c').to.not.contain('f');
Code.expect(function () {}).to.not.throw().and.to.be.a.function();
Code.expect(() => {}).to.not.throw().and.to.be.a.function();
Code.expect(10).to.not.be.about(8, 1).and.to.be.about(9, 1);

@@ -308,6 +322,6 @@ Code.expect(10).to.be.about(9, 1).and.to.not.be.about(8, 1);

it('uses the global prototype setting when doing deep compares on objects', function (done) {
it('uses the global prototype setting when doing deep compares on objects', (done) => {
var origPrototype = Code.settings.comparePrototypes;
var exception = false;
const origPrototype = Code.settings.comparePrototypes;
let exception = false;

@@ -318,3 +332,3 @@ Code.settings.comparePrototypes = false;

var obj = Object.create(null);
const obj = Object.create(null);
Code.expect({}).to.deep.equal(obj);

@@ -334,9 +348,9 @@ obj.foo = 'bar';

describe('assertion', function () {
describe('assertion', () => {
describe('argument()', function () {
describe('argument()', () => {
it('validates correct type', function (done) {
it('validates correct type', (done) => {
var grab = function () {
const grab = function () {

@@ -346,3 +360,3 @@ return arguments;

var exception = false;
let exception = false;
try {

@@ -359,5 +373,5 @@ Code.expect(grab(1, 2, 3)).to.be.arguments();

it('invalidates incorrect type', function (done) {
it('invalidates incorrect type', (done) => {
var exception = false;
let exception = false;
try {

@@ -375,7 +389,7 @@ Code.expect({ 1: 1, 2: 2, 3: 3, length: 3 }).to.be.arguments();

describe('array()', function () {
describe('array()', () => {
it('validates correct type', function (done) {
it('validates correct type', (done) => {
var exception = false;
let exception = false;
try {

@@ -392,5 +406,5 @@ Code.expect([1]).to.be.an.array();

it('invalidates incorrect type', function (done) {
it('invalidates incorrect type', (done) => {
var exception = false;
let exception = false;
try {

@@ -408,7 +422,7 @@ Code.expect({ 1: 1 }).to.be.an.array();

describe('boolean()', function () {
describe('boolean()', () => {
it('validates correct type', function (done) {
it('validates correct type', (done) => {
var exception = false;
let exception = false;
try {

@@ -425,5 +439,5 @@ Code.expect(true).to.be.a.boolean();

it('invalidates incorrect type', function (done) {
it('invalidates incorrect type', (done) => {
var exception = false;
let exception = false;
try {

@@ -441,7 +455,7 @@ Code.expect(undefined).to.be.a.boolean();

describe('buffer()', function () {
describe('buffer()', () => {
it('validates correct type', function (done) {
it('validates correct type', (done) => {
var exception = false;
let exception = false;
try {

@@ -458,5 +472,5 @@ Code.expect(new Buffer([1])).to.be.a.buffer();

it('invalidates incorrect type', function (done) {
it('invalidates incorrect type', (done) => {
var exception = false;
let exception = false;
try {

@@ -474,7 +488,7 @@ Code.expect(null).to.be.a.buffer();

describe('date()', function () {
describe('date()', () => {
it('validates correct type', function (done) {
it('validates correct type', (done) => {
var exception = false;
let exception = false;
try {

@@ -491,5 +505,5 @@ Code.expect(new Date()).to.be.a.date();

it('invalidates incorrect type', function (done) {
it('invalidates incorrect type', (done) => {
var exception = false;
let exception = false;
try {

@@ -507,9 +521,9 @@ Code.expect(true).to.be.a.date();

describe('function()', function () {
describe('function()', () => {
it('validates correct type', function (done) {
it('validates correct type', (done) => {
var exception = false;
let exception = false;
try {
Code.expect(function () { }).to.be.a.function();
Code.expect(() => { }).to.be.a.function();
}

@@ -524,5 +538,5 @@ catch (err) {

it('invalidates incorrect type', function (done) {
it('invalidates incorrect type', (done) => {
var exception = false;
let exception = false;
try {

@@ -540,7 +554,7 @@ Code.expect(false).to.be.a.function();

describe('number()', function () {
describe('number()', () => {
it('validates correct type', function (done) {
it('validates correct type', (done) => {
var exception = false;
let exception = false;
try {

@@ -557,7 +571,7 @@ Code.expect(22).to.be.a.number();

it('invalidates incorrect type', function (done) {
it('invalidates incorrect type', (done) => {
var exception = false;
let exception = false;
try {
Code.expect(function () { }).to.be.a.number();
Code.expect(() => { }).to.be.a.number();
}

@@ -573,7 +587,7 @@ catch (err) {

describe('regexp()', function () {
describe('regexp()', () => {
it('validates correct type', function (done) {
it('validates correct type', (done) => {
var exception = false;
let exception = false;
try {

@@ -590,5 +604,5 @@ Code.expect(/a/).to.be.a.regexp();

it('invalidates incorrect type', function (done) {
it('invalidates incorrect type', (done) => {
var exception = false;
let exception = false;
try {

@@ -606,7 +620,7 @@ Code.expect(new Date()).to.be.a.regexp();

describe('string()', function () {
describe('string()', () => {
it('validates correct type', function (done) {
it('validates correct type', (done) => {
var exception = false;
let exception = false;
try {

@@ -623,5 +637,5 @@ Code.expect('asd').to.be.a.string();

it('invalidates incorrect type', function (done) {
it('invalidates incorrect type', (done) => {
var exception = false;
let exception = false;
try {

@@ -639,7 +653,7 @@ Code.expect(/a/).to.be.a.string();

describe('object()', function () {
describe('object()', () => {
it('validates correct type', function (done) {
it('validates correct type', (done) => {
var exception = false;
let exception = false;
try {

@@ -656,5 +670,5 @@ Code.expect({}).to.be.a.object();

it('invalidates incorrect type', function (done) {
it('invalidates incorrect type', (done) => {
var exception = false;
let exception = false;
try {

@@ -672,7 +686,7 @@ Code.expect(new Buffer([20])).to.be.an.object();

describe('true()', function () {
describe('true()', () => {
it('validates correct type', function (done) {
it('validates correct type', (done) => {
var exception = false;
let exception = false;
try {

@@ -689,5 +703,5 @@ Code.expect(true).to.be.true();

it('invalidates incorrect type', function (done) {
it('invalidates incorrect type', (done) => {
var exception = false;
let exception = false;
try {

@@ -705,7 +719,7 @@ Code.expect('a').to.be.true();

describe('false()', function () {
describe('false()', () => {
it('validates correct type', function (done) {
it('validates correct type', (done) => {
var exception = false;
let exception = false;
try {

@@ -722,5 +736,5 @@ Code.expect(false).to.be.false();

it('invalidates incorrect type', function (done) {
it('invalidates incorrect type', (done) => {
var exception = false;
let exception = false;
try {

@@ -738,7 +752,7 @@ Code.expect('a').to.be.false();

describe('null()', function () {
describe('null()', () => {
it('validates correct type', function (done) {
it('validates correct type', (done) => {
var exception = false;
let exception = false;
try {

@@ -755,5 +769,5 @@ Code.expect(null).to.be.null();

it('invalidates incorrect type', function (done) {
it('invalidates incorrect type', (done) => {
var exception = false;
let exception = false;
try {

@@ -771,7 +785,7 @@ Code.expect('a').to.be.null();

describe('undefined()', function () {
describe('undefined()', () => {
it('validates correct type', function (done) {
it('validates correct type', (done) => {
var exception = false;
let exception = false;
try {

@@ -788,5 +802,5 @@ Code.expect(undefined).to.be.undefined();

it('validates correct type (missing)', function (done) {
it('validates correct type (missing)', (done) => {
var exception = false;
let exception = false;
try {

@@ -803,5 +817,5 @@ Code.expect().to.be.undefined();

it('invalidates incorrect type', function (done) {
it('invalidates incorrect type', (done) => {
var exception = false;
let exception = false;
try {

@@ -819,7 +833,7 @@ Code.expect('a').to.be.undefined();

describe('include()', function () {
describe('include()', () => {
it('validates strings', function (done) {
it('validates strings', (done) => {
var exception = false;
let exception = false;
try {

@@ -841,5 +855,5 @@ Code.expect('abc').to.include('ab');

it('validates arrays', function (done) {
it('validates arrays', (done) => {
var exception = false;
let exception = false;
try {

@@ -863,5 +877,5 @@ Code.expect([1, 2, 3]).to.include(1);

it('validates objects', function (done) {
it('validates objects', (done) => {
var exception = false;
let exception = false;
try {

@@ -885,5 +899,5 @@ Code.expect({ a: 1, b: 2, c: 3 }).to.include('a');

it('validates aliases', function (done) {
it('validates aliases', (done) => {
var exception = false;
let exception = false;
try {

@@ -903,7 +917,7 @@ Code.expect('abc').to.includes('ab');

describe('endWith()', function () {
describe('endWith()', () => {
it('validates strings', function (done) {
it('validates strings', (done) => {
var exception = false;
let exception = false;
try {

@@ -922,5 +936,5 @@ Code.expect('http://xyz.abc/def').to.endWith('abc/def');

it('does not validate arrays', function (done) {
it('does not validate arrays', (done) => {
var exception = false;
let exception = false;
try {

@@ -937,5 +951,5 @@ Code.expect(['a', 'b', 'c']).to.endWith('abcdef');

it('does not validate using arrays', function (done) {
it('does not validate using arrays', (done) => {
var exception = false;
let exception = false;
try {

@@ -954,7 +968,7 @@ Code.expect('abcdef').to.endWith(['a', 'b', 'c']);

describe('startWith()', function () {
describe('startWith()', () => {
it('validates strings', function (done) {
it('validates strings', (done) => {
var exception = false;
let exception = false;
try {

@@ -976,5 +990,5 @@ Code.expect('http://xyz.abc/def').to.startWith('http://');

it('does not validate arrays', function (done) {
it('does not validate arrays', (done) => {
var exception = false;
let exception = false;
try {

@@ -991,5 +1005,5 @@ Code.expect(['a', 'b', 'c']).to.startWith('abcdef');

it('does not validate using arrays', function (done) {
it('does not validate using arrays', (done) => {
var exception = false;
let exception = false;
try {

@@ -1008,7 +1022,7 @@ Code.expect('abcdef').to.startWith(['a', 'b', 'c']);

describe('exist()', function () {
describe('exist()', () => {
it('validates assertion', function (done) {
it('validates assertion', (done) => {
var exception = false;
let exception = false;
try {

@@ -1025,5 +1039,5 @@ Code.expect('a').to.exist();

it('invalidates assertion (null)', function (done) {
it('invalidates assertion (null)', (done) => {
var exception = false;
let exception = false;
try {

@@ -1040,5 +1054,5 @@ Code.expect(null).to.be.exist();

it('invalidates assertion (undefined)', function (done) {
it('invalidates assertion (undefined)', (done) => {
var exception = false;
let exception = false;
try {

@@ -1055,5 +1069,5 @@ Code.expect(undefined).to.be.exist();

it('validates assertion (alias)', function (done) {
it('validates assertion (alias)', (done) => {
var exception = false;
let exception = false;
try {

@@ -1070,5 +1084,5 @@ Code.expect('a').exists();

it('validates assertion (not error)', function (done) {
it('validates assertion (not error)', (done) => {
var exception = false;
let exception = false;
try {

@@ -1086,7 +1100,7 @@ Code.expect(new Error('some message')).to.not.exist();

describe('empty()', function () {
describe('empty()', () => {
it('validates string', function (done) {
it('validates string', (done) => {
var exception = false;
let exception = false;
try {

@@ -1103,5 +1117,5 @@ Code.expect('').to.be.empty();

it('validates buffer', function (done) {
it('validates buffer', (done) => {
var exception = false;
let exception = false;
try {

@@ -1118,5 +1132,5 @@ Code.expect(new Buffer('')).to.be.empty();

it('validates array', function (done) {
it('validates array', (done) => {
var exception = false;
let exception = false;
try {

@@ -1133,5 +1147,5 @@ Code.expect([]).to.be.empty();

it('validates object', function (done) {
it('validates object', (done) => {
var exception = false;
let exception = false;
try {

@@ -1148,5 +1162,5 @@ Code.expect({}).to.be.empty();

it('invalidates incorrect type', function (done) {
it('invalidates incorrect type', (done) => {
var exception = false;
let exception = false;
try {

@@ -1164,7 +1178,7 @@ Code.expect('a').to.be.empty();

describe('length()', function () {
describe('length()', () => {
it('validates string', function (done) {
it('validates string', (done) => {
var exception = false;
let exception = false;
try {

@@ -1181,5 +1195,5 @@ Code.expect('a').to.have.length(1);

it('validates buffer', function (done) {
it('validates buffer', (done) => {
var exception = false;
let exception = false;
try {

@@ -1196,5 +1210,5 @@ Code.expect(new Buffer('a')).to.have.length(1);

it('validates array', function (done) {
it('validates array', (done) => {
var exception = false;
let exception = false;
try {

@@ -1211,5 +1225,5 @@ Code.expect([1]).to.have.length(1);

it('validates object', function (done) {
it('validates object', (done) => {
var exception = false;
let exception = false;
try {

@@ -1226,5 +1240,5 @@ Code.expect({ a: 10 }).to.have.length(1);

it('invalidates incorrect type', function (done) {
it('invalidates incorrect type', (done) => {
var exception = false;
let exception = false;
try {

@@ -1242,7 +1256,7 @@ Code.expect('a').to.have.length(10);

describe('equal()', function () {
describe('equal()', () => {
it('validates assertion', function (done) {
it('validates assertion', (done) => {
var exception = false;
let exception = false;
try {

@@ -1259,5 +1273,5 @@ Code.expect('abc').to.equal('abc');

it('validates assertion (alias)', function (done) {
it('validates assertion (alias)', (done) => {
var exception = false;
let exception = false;
try {

@@ -1274,5 +1288,5 @@ Code.expect('abc').equals('abc');

it('validates assertion (deep)', function (done) {
it('validates assertion (deep)', (done) => {
var exception = false;
let exception = false;
try {

@@ -1294,5 +1308,5 @@ Code.expect(['abc']).to.deep.equal(['abc']);

it('invalidates assertion', function (done) {
it('invalidates assertion', (done) => {
var exception = false;
let exception = false;
try {

@@ -1310,7 +1324,7 @@ Code.expect(['a']).to.equal(['a']);

describe('above()', function () {
describe('above()', () => {
it('validates assertion', function (done) {
it('validates assertion', (done) => {
var exception = false;
let exception = false;
try {

@@ -1327,5 +1341,5 @@ Code.expect(10).to.be.above(5);

it('validates assertion (alias)', function (done) {
it('validates assertion (alias)', (done) => {
var exception = false;
let exception = false;
try {

@@ -1342,5 +1356,5 @@ Code.expect(1).to.be.greaterThan(0);

it('invalidates assertion', function (done) {
it('invalidates assertion', (done) => {
var exception = false;
let exception = false;
try {

@@ -1358,7 +1372,7 @@ Code.expect(10).to.be.above(50);

describe('least()', function () {
describe('least()', () => {
it('validates assertion', function (done) {
it('validates assertion', (done) => {
var exception = false;
let exception = false;
try {

@@ -1375,5 +1389,5 @@ Code.expect(10).to.be.at.least(10);

it('validates assertion (alias)', function (done) {
it('validates assertion (alias)', (done) => {
var exception = false;
let exception = false;
try {

@@ -1390,5 +1404,5 @@ Code.expect(10).to.be.min(10);

it('invalidates assertion', function (done) {
it('invalidates assertion', (done) => {
var exception = false;
let exception = false;
try {

@@ -1406,7 +1420,7 @@ Code.expect(10).to.be.at.least(20);

describe('below()', function () {
describe('below()', () => {
it('validates assertion', function (done) {
it('validates assertion', (done) => {
var exception = false;
let exception = false;
try {

@@ -1423,5 +1437,5 @@ Code.expect(1).to.be.below(10);

it('validates assertion (alias)', function (done) {
it('validates assertion (alias)', (done) => {
var exception = false;
let exception = false;
try {

@@ -1438,5 +1452,5 @@ Code.expect(1).to.be.lessThan(10);

it('invalidates assertion', function (done) {
it('invalidates assertion', (done) => {
var exception = false;
let exception = false;
try {

@@ -1454,7 +1468,7 @@ Code.expect(1).to.be.below(0);

describe('most()', function () {
describe('most()', () => {
it('validates assertion', function (done) {
it('validates assertion', (done) => {
var exception = false;
let exception = false;
try {

@@ -1471,5 +1485,5 @@ Code.expect(10).to.be.at.most(10);

it('validates assertion (alias)', function (done) {
it('validates assertion (alias)', (done) => {
var exception = false;
let exception = false;
try {

@@ -1486,5 +1500,5 @@ Code.expect(10).to.be.max(10);

it('invalidates assertion', function (done) {
it('invalidates assertion', (done) => {
var exception = false;
let exception = false;
try {

@@ -1502,7 +1516,7 @@ Code.expect(100).to.be.at.most(20);

describe('within()', function () {
describe('within()', () => {
it('validates assertion', function (done) {
it('validates assertion', (done) => {
var exception = false;
let exception = false;
try {

@@ -1521,5 +1535,5 @@ Code.expect(5).to.be.within(0, 10);

it('validates assertion (alias)', function (done) {
it('validates assertion (alias)', (done) => {
var exception = false;
let exception = false;
try {

@@ -1536,5 +1550,5 @@ Code.expect(5).to.be.in.range(0, 10);

it('invalidates assertion (over)', function (done) {
it('invalidates assertion (over)', (done) => {
var exception = false;
let exception = false;
try {

@@ -1551,5 +1565,5 @@ Code.expect(5).to.be.within(0, 4);

it('invalidates assertion (under)', function (done) {
it('invalidates assertion (under)', (done) => {
var exception = false;
let exception = false;
try {

@@ -1567,7 +1581,7 @@ Code.expect(-1).to.be.within(0, 4);

describe('between()', function () {
describe('between()', () => {
it('validates assertion', function (done) {
it('validates assertion', (done) => {
var exception = false;
let exception = false;
try {

@@ -1584,5 +1598,5 @@ Code.expect(5).to.be.between(0, 10);

it('invalidates assertion (over)', function (done) {
it('invalidates assertion (over)', (done) => {
var exception = false;
let exception = false;
try {

@@ -1599,5 +1613,5 @@ Code.expect(4).to.be.between(0, 4);

it('invalidates assertion (under)', function (done) {
it('invalidates assertion (under)', (done) => {
var exception = false;
let exception = false;
try {

@@ -1615,7 +1629,7 @@ Code.expect(0).to.be.between(0, 4);

describe('about()', function () {
describe('about()', () => {
it('validates assertion', function (done) {
it('validates assertion', (done) => {
var exception = false;
let exception = false;
try {

@@ -1632,5 +1646,5 @@ Code.expect(10).to.be.about(8, 2);

it('invalidates assertion', function (done) {
it('invalidates assertion', (done) => {
var exception = false;
let exception = false;
try {

@@ -1647,5 +1661,5 @@ Code.expect(10).to.be.about(8, 1);

it('invalidates assertion (invalid arguments)', function (done) {
it('invalidates assertion (invalid arguments)', (done) => {
var exception = false;
let exception = false;
try {

@@ -1663,7 +1677,7 @@ Code.expect(10).to.be.about('8', '1');

describe('instanceof()', function () {
describe('instanceof()', () => {
it('validates assertion', function (done) {
it('validates assertion', (done) => {
var exception = false;
let exception = false;
try {

@@ -1680,5 +1694,5 @@ Code.expect(new Date()).to.be.instanceof(Date);

it('validates assertion (alias)', function (done) {
it('validates assertion (alias)', (done) => {
var exception = false;
let exception = false;
try {

@@ -1695,5 +1709,5 @@ Code.expect(new Date()).to.be.instanceOf(Date);

it('invalidates assertion', function (done) {
it('invalidates assertion', (done) => {
var exception = false;
let exception = false;
try {

@@ -1710,7 +1724,7 @@ Code.expect([]).to.be.instanceof(RegExp);

it('invalidates assertion (anonymous)', function (done) {
it('invalidates assertion (anonymous)', (done) => {
var Custom = function () { };
const Custom = function () { };
var exception = false;
let exception = false;
try {

@@ -1727,7 +1741,7 @@ Code.expect([]).to.be.instanceof(Custom);

it('invalidates assertion (anonymous)', function (done) {
it('invalidates assertion (anonymous)', (done) => {
function Custom () { } /* eslint func-style:0 */
var exception = false;
let exception = false;
try {

@@ -1745,7 +1759,7 @@ Code.expect([]).to.be.instanceof(Custom);

describe('match()', function () {
describe('match()', () => {
it('validates assertion', function (done) {
it('validates assertion', (done) => {
var exception = false;
let exception = false;
try {

@@ -1762,5 +1776,5 @@ Code.expect('a4x').to.match(/\w\dx/);

it('validates assertion (alias)', function (done) {
it('validates assertion (alias)', (done) => {
var exception = false;
let exception = false;
try {

@@ -1777,5 +1791,5 @@ Code.expect('a4x').matches(/\w\dx/);

it('invalidates assertion', function (done) {
it('invalidates assertion', (done) => {
var exception = false;
let exception = false;
try {

@@ -1793,5 +1807,5 @@ Code.expect('a4x').to.match(/\w\dy/);

describe('satisfy()', function () {
describe('satisfy()', () => {
var validate = function (value) {
const validate = function (value) {

@@ -1801,5 +1815,5 @@ return value === 'some value';

it('validates assertion', function (done) {
it('validates assertion', (done) => {
var exception = false;
let exception = false;
try {

@@ -1816,5 +1830,5 @@ Code.expect('some value').to.satisfy(validate);

it('validates assertion (alias)', function (done) {
it('validates assertion (alias)', (done) => {
var exception = false;
let exception = false;
try {

@@ -1831,5 +1845,5 @@ Code.expect('some value').satisfies(validate);

it('invalidates assertion', function (done) {
it('invalidates assertion', (done) => {
var exception = false;
let exception = false;
try {

@@ -1847,5 +1861,5 @@ Code.expect('wrong').to.satisfy(validate);

describe('throw()', function () {
describe('throw()', () => {
var throws = function () {
const throws = function () {

@@ -1855,5 +1869,5 @@ throw new Error('kaboom');

it('validates assertion', function (done) {
it('validates assertion', (done) => {
var exception = false;
let exception = false;
try {

@@ -1870,5 +1884,5 @@ Code.expect(throws).to.throw();

it('validates assertion (alias)', function (done) {
it('validates assertion (alias)', (done) => {
var exception = false;
let exception = false;
try {

@@ -1885,7 +1899,7 @@ Code.expect(throws).throws();

it('invalidates assertion', function (done) {
it('invalidates assertion', (done) => {
var exception = false;
let exception = false;
try {
Code.expect(function () { }).to.throw();
Code.expect(() => { }).to.throw();
}

@@ -1900,7 +1914,7 @@ catch (err) {

it('forbids arguments on negative assertion', function (done) {
it('forbids arguments on negative assertion', (done) => {
var exception = false;
let exception = false;
try {
Code.expect(function () { }).to.not.throw('message');
Code.expect(() => { }).to.not.throw('message');
}

@@ -1915,5 +1929,5 @@ catch (err) {

it('validates assertion (message)', function (done) {
it('validates assertion (message)', (done) => {
var exception = false;
let exception = false;
try {

@@ -1930,7 +1944,7 @@ Code.expect(throws).to.throw('kaboom');

it('validates assertion (empty message)', function (done) {
it('validates assertion (empty message)', (done) => {
var exception = false;
let exception = false;
try {
Code.expect(function () {
Code.expect(() => {

@@ -1948,5 +1962,5 @@ throw new Error('');

it('validates assertion (message regex)', function (done) {
it('validates assertion (message regex)', (done) => {
var exception = false;
let exception = false;
try {

@@ -1963,9 +1977,9 @@ Code.expect(throws).to.throw(/boom/);

it('validates assertion (missing message)', function (done) {
it('validates assertion (missing message)', (done) => {
var Custom = function () { };
const Custom = function () { };
var exception = false;
let exception = false;
try {
Code.expect(function () {
Code.expect(() => {

@@ -1983,7 +1997,7 @@ throw new Custom();

it('invalidates assertion (message)', function (done) {
it('invalidates assertion (message)', (done) => {
var exception = false;
let exception = false;
try {
Code.expect(function () { }).to.throw('steve');
Code.expect(() => { }).to.throw('steve');
}

@@ -1998,7 +2012,7 @@ catch (err) {

it('invalidates assertion (empty message)', function (done) {
it('invalidates assertion (empty message)', (done) => {
var exception = false;
let exception = false;
try {
Code.expect(function () {
Code.expect(() => {

@@ -2016,5 +2030,5 @@ throw new Error('kaboom');

it('validates assertion (type)', function (done) {
it('validates assertion (type)', (done) => {
var exception = false;
let exception = false;
try {

@@ -2031,9 +2045,9 @@ Code.expect(throws).to.throw(Error);

it('invalidates assertion (known type)', function (done) {
it('invalidates assertion (known type)', (done) => {
var Custom = function () { };
const Custom = function () { };
var exception = false;
let exception = false;
try {
Code.expect(function () {
Code.expect(() => {

@@ -2051,7 +2065,7 @@ throw new Custom();

it('invalidates assertion (anonymous type)', function (done) {
it('invalidates assertion (anonymous type)', (done) => {
var Custom = function () { };
const Custom = function () { };
var exception = false;
let exception = false;
try {

@@ -2068,5 +2082,5 @@ Code.expect(throws).to.throw(Custom);

it('validates assertion (type and message)', function (done) {
it('validates assertion (type and message)', (done) => {
var exception = false;
let exception = false;
try {

@@ -2086,7 +2100,7 @@ Code.expect(throws).to.throw(Error, 'kaboom');

describe('incomplete()', function () {
describe('incomplete()', () => {
it('keeps track of incomplete assertions', function (done) {
it('keeps track of incomplete assertions', (done) => {
var a = Code.expect(1).to;
const a = Code.expect(1).to;
Code.expect(2).to.equal(2);

@@ -2093,0 +2107,0 @@ Hoek.assert(Code.incomplete().length === 1);

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

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