Comparing version 0.5.2 to 0.5.3
{ | ||
"name": "lazy-ass", | ||
"main": "index.js", | ||
"version": "0.5.2", | ||
"version": "0.5.3", | ||
"homepage": "https://github.com/bahmutov/lazy-ass", | ||
@@ -6,0 +6,0 @@ "license": "MIT", |
@@ -34,3 +34,9 @@ (function initLazyAss() { | ||
} | ||
return total + JSON.stringify(arg, null, 2); | ||
var argString; | ||
try { | ||
argString = JSON.stringify(arg, null, 2); | ||
} catch (err) { | ||
argString = '[cannot stringify arg ' + k + ']'; | ||
} | ||
return total + argString; | ||
}, ''); | ||
@@ -37,0 +43,0 @@ return msg; |
@@ -1,4 +0,24 @@ | ||
// Karma configuration | ||
// Generated on Fri Apr 04 2014 22:41:07 GMT-0400 (EDT) | ||
// single run: | ||
// karma start karma.conf.js | ||
// continuous watch and rerun on file changes using PhantomJS | ||
// karma start karma.conf.js --single-run=false --browsers=PhantomJS | ||
// single run using Chrome (not run by default) | ||
// karma start karma.conf.js --browsers=Chrome | ||
// continuous run using Chrome | ||
// karma start karma.conf.js --single-run=false --browsers=Chrome | ||
// if you want to debug source code in the browser and do not need coverage | ||
// karma start karma.conf.js --single-run=false --browsers=Chrome --debug | ||
var sourcePreprocessors = 'coverage'; | ||
function isDebug(argument) { | ||
return argument === '--debug'; | ||
} | ||
if (process.argv.some(isDebug)) { | ||
sourcePreprocessors = []; | ||
} | ||
module.exports = function (config) { | ||
@@ -28,3 +48,3 @@ config.set({ | ||
preprocessors: { | ||
'index.js': 'coverage', | ||
'index.js': sourcePreprocessors, | ||
}, | ||
@@ -31,0 +51,0 @@ |
{ | ||
"name": "lazy-ass", | ||
"description": "Lazy assertions without performance penalty", | ||
"version": "0.5.2", | ||
"version": "0.5.3", | ||
"author": "Gleb Bahmutov <gleb.bahmutov@gmail.com>", | ||
@@ -28,2 +28,3 @@ "bugs": { | ||
"karma": "0.12.16", | ||
"karma-chrome-launcher": "0.1.4", | ||
"karma-coverage": "0.2.2", | ||
@@ -30,0 +31,0 @@ "karma-mocha": "0.1.3", |
@@ -55,5 +55,7 @@ # lazy-ass | ||
Node: `npm install lazy-ass --save` then `var lazyAss = require('lazy-ass');` | ||
Node: `npm install lazy-ass --save` then `require('lazy-ass');`, | ||
attaches functions `lazyAss` and `la` to `global` object. | ||
Browser: `bower install lazy-ass --save`, makes function available as `window.lazyAss`. | ||
Browser: `bower install lazy-ass --save`, include `index.js`, | ||
attaches functions `lazyAss` and `la` to `window` object. | ||
@@ -60,0 +62,0 @@ ## Notes |
/* global lazyAss, la */ | ||
if (typeof window === 'undefined') { | ||
require('..'); // Node | ||
} | ||
if (typeof lazyAss === 'undefined') { | ||
throw new Error('Cannot find lazyAss global varible'); | ||
} | ||
if (typeof expect === 'undefined') { | ||
var expect = require('expect.js'); | ||
} | ||
(function (root) { | ||
if (typeof window === 'undefined') { | ||
require('..'); // Node | ||
} | ||
if (typeof lazyAss === 'undefined') { | ||
throw new Error('Cannot find lazyAss global varible'); | ||
} | ||
if (typeof root.expect === 'undefined') { | ||
root.expect = require('expect.js'); | ||
} | ||
describe('lazyAss', function () { | ||
describe('lazyAss function itself', function () { | ||
it('is a function', function () { | ||
expect(lazyAss).not.to.be(undefined); | ||
expect(lazyAss).to.be.a('function'); | ||
}); | ||
var expect = root.expect; | ||
it('has alias', function () { | ||
expect(la).to.be.a('function'); | ||
}); | ||
describe('lazyAss', function () { | ||
describe('lazyAss function itself', function () { | ||
it('is a function', function () { | ||
expect(lazyAss).not.to.be(undefined); | ||
expect(lazyAss).to.be.a('function'); | ||
}); | ||
it('does not throw if condition is true', function () { | ||
expect(function () { | ||
lazyAss(true); | ||
}).not.to.throwError(); | ||
}); | ||
it('has alias', function () { | ||
expect(la).to.be.a('function'); | ||
}); | ||
it('does not evaluate function if condition is true', function () { | ||
function foo() { | ||
throw new Error('Foo has been called'); | ||
} | ||
lazyAss(true, foo); | ||
}); | ||
it('does not throw if condition is true', function () { | ||
expect(function () { | ||
lazyAss(true); | ||
}).not.to.throwError(); | ||
}); | ||
it('throws error with string', function () { | ||
expect(function () { | ||
lazyAss(false, 'foo'); | ||
}).to.throwException(/^foo$/); | ||
}); | ||
it('does not evaluate function if condition is true', function () { | ||
function foo() { | ||
throw new Error('Foo has been called'); | ||
} | ||
lazyAss(true, foo); | ||
}); | ||
it('adds spaces', function () { | ||
expect(function () { | ||
lazyAss(false, 'foo', 'bar'); | ||
}).to.throwException(/^foo bar$/); | ||
}); | ||
it('throws error with string', function () { | ||
expect(function () { | ||
lazyAss(false, 'foo'); | ||
}).to.throwException(/^foo$/); | ||
}); | ||
it('calls functions to form message', function () { | ||
var called = 0; | ||
function foo() { | ||
called += 1; | ||
return 'foo'; | ||
} | ||
expect(function () { | ||
lazyAss(false, foo, 'bar', foo); | ||
}).to.throwException(/^foo bar foo$/); | ||
}); | ||
it('adds spaces', function () { | ||
expect(function () { | ||
lazyAss(false, 'foo', 'bar'); | ||
}).to.throwException(/^foo bar$/); | ||
}); | ||
it('calls function each time', function () { | ||
var called = 0; | ||
function foo() { | ||
called += 1; | ||
return 'foo'; | ||
} | ||
expect(function () { | ||
lazyAss(false, foo, 'bar', foo); | ||
}).to.throwException(function () { | ||
expect(called).to.equal(2); | ||
it('calls functions to form message', function () { | ||
var called = 0; | ||
function foo() { | ||
called += 1; | ||
return 'foo'; | ||
} | ||
expect(function () { | ||
lazyAss(false, foo, 'bar', foo); | ||
}).to.throwException(/^foo bar foo$/); | ||
}); | ||
}); | ||
it('handles exception if thrown from function', function () { | ||
var called = 0; | ||
function foo() { | ||
called += 1; | ||
throw new Error('Oh no!'); | ||
} | ||
expect(function () { | ||
lazyAss(false, foo, 'bar', foo); | ||
}).to.throwException(function (err) { | ||
expect(called).to.equal(2); | ||
expect(err.message).to.contain('bar'); | ||
it('calls function each time', function () { | ||
var called = 0; | ||
function foo() { | ||
called += 1; | ||
return 'foo'; | ||
} | ||
expect(function () { | ||
lazyAss(false, foo, 'bar', foo); | ||
}).to.throwException(function () { | ||
expect(called).to.equal(2); | ||
}); | ||
}); | ||
}); | ||
it('JSON stringifies arrays', function () { | ||
expect(function () { | ||
lazyAss(false, [1, 2, 3]); | ||
}).to.throwException(/^\[1,2,3\]$/); | ||
}); | ||
it('handles exception if thrown from function', function () { | ||
var called = 0; | ||
function foo() { | ||
called += 1; | ||
throw new Error('Oh no!'); | ||
} | ||
expect(function () { | ||
lazyAss(false, foo, 'bar', foo); | ||
}).to.throwException(function (err) { | ||
expect(called).to.equal(2); | ||
expect(err.message).to.contain('bar'); | ||
}); | ||
}); | ||
it('JSON stringifies objects', function () { | ||
var obj = { foo: 'foo' }; | ||
expect(function () { | ||
lazyAss(false, obj); | ||
}).to.throwException(JSON.stringify(obj, null, 2)); | ||
}); | ||
it('JSON stringifies arrays', function () { | ||
expect(function () { | ||
lazyAss(false, [1, 2, 3]); | ||
}).to.throwException(/^\[1,2,3\]$/); | ||
}); | ||
it('takes error name and message', function () { | ||
expect(function () { | ||
lazyAss(false, new Error('hi there')); | ||
}).to.throwException(function (err) { | ||
expect(err.message).to.contain('Error'); | ||
expect(err.message).to.contain('hi there'); | ||
it('JSON stringifies objects', function () { | ||
var obj = { foo: 'foo' }; | ||
expect(function () { | ||
lazyAss(false, obj); | ||
}).to.throwException(JSON.stringify(obj, null, 2)); | ||
}); | ||
it('takes error name and message', function () { | ||
expect(function () { | ||
lazyAss(false, new Error('hi there')); | ||
}).to.throwException(function (err) { | ||
expect(err.message).to.contain('Error'); | ||
expect(err.message).to.contain('hi there'); | ||
}); | ||
}); | ||
}); | ||
}); | ||
describe('function as condition', function () { | ||
it('evaluates the function', function () { | ||
var called; | ||
function condition() { called = true; return true; } | ||
describe('function as condition', function () { | ||
it('evaluates the function', function () { | ||
var called; | ||
function condition() { called = true; return true; } | ||
lazyAss(condition); | ||
expect(called).to.be(true); | ||
}); | ||
lazyAss(condition); | ||
expect(called).to.be(true); | ||
}); | ||
it('no result is failure', function () { | ||
function noreturn() {} | ||
it('no result is failure', function () { | ||
function noreturn() {} | ||
expect(function () { | ||
lazyAss(noreturn); | ||
}).to.throwError(); | ||
}); | ||
expect(function () { | ||
lazyAss(noreturn); | ||
}).to.throwError(); | ||
}); | ||
it('adds condition function source to message', function () { | ||
function myCondition() {} | ||
expect(function () { | ||
lazyAss(myCondition); | ||
}).to.throwException(/myCondition/); | ||
}); | ||
it('adds condition function source to message', function () { | ||
function myCondition() {} | ||
expect(function () { | ||
lazyAss(myCondition); | ||
}).to.throwException(/myCondition/); | ||
}); | ||
it('allows anonymous functions', function () { | ||
var called; | ||
lazyAss(function() { return true; }); | ||
lazyAss(function() { return true; }, 'everything is ok'); | ||
lazyAss(function() { called = true; return true; }, 'everything is ok'); | ||
expect(called).to.be(true); | ||
it('allows anonymous functions', function () { | ||
var called; | ||
lazyAss(function() { return true; }); | ||
lazyAss(function() { return true; }, 'everything is ok'); | ||
lazyAss(function() { called = true; return true; }, 'everything is ok'); | ||
expect(called).to.be(true); | ||
expect(function () { | ||
lazyAss(function () {}); | ||
}).to.throwError(); | ||
expect(function () { | ||
lazyAss(function () {}); | ||
}).to.throwError(); | ||
}); | ||
it('has access via closure', function () { | ||
var foo = 2, bar = 3; | ||
expect(function () { | ||
lazyAss(function () { return foo + bar === 6; }, 'addition'); | ||
}).to.throwException(function (err) { | ||
expect(err.message).to.contain('foo + bar'); | ||
expect(err.message).to.contain('addition'); | ||
}); | ||
}); | ||
it('example', function () { | ||
var foo = 2, bar = 2; | ||
function isValidPair() { | ||
return foo + bar === 4; | ||
} | ||
lazyAss(isValidPair, 'foo', foo, 'bar', bar); | ||
}); | ||
}); | ||
it('has access via closure', function () { | ||
var foo = 2, bar = 3; | ||
expect(function () { | ||
lazyAss(function () { return foo + bar === 6; }, 'addition'); | ||
}).to.throwException(function (err) { | ||
expect(err.message).to.contain('foo + bar'); | ||
expect(err.message).to.contain('addition'); | ||
describe('serializes circular objects', function () { | ||
var foo = { | ||
bar: 'bar' | ||
}; | ||
foo.foo = foo; | ||
it('can handle circular object', function () { | ||
var msg = 'foo has circular reference'; | ||
expect(function () { | ||
lazyAss(false, msg, foo); | ||
}).to.throwException(function (err) { | ||
expect(err.message).to.contain(msg); | ||
}); | ||
}); | ||
}); | ||
it('example', function () { | ||
var foo = 2, bar = 2; | ||
function isValidPair() { | ||
return foo + bar === 4; | ||
describe('serialize arguments', function () { | ||
function foo() { | ||
la(false, arguments); | ||
} | ||
lazyAss(isValidPair, 'foo', foo, 'bar', bar); | ||
it('serializes arguments object', function () { | ||
expect(function () { | ||
foo('something'); | ||
}).to.throwException(/something/); | ||
}); | ||
}); | ||
}); | ||
describe('serialize arguments', function () { | ||
function foo() { | ||
la(false, arguments); | ||
} | ||
it('serializes arguments object', function () { | ||
expect(function () { | ||
foo('something'); | ||
}).to.throwException(/something/); | ||
}); | ||
}); | ||
}); | ||
}(this)); |
/* global lazyAssync, lac */ | ||
if (typeof window === 'undefined') { | ||
require('..'); // Node | ||
} | ||
if (typeof lazyAssync === 'undefined') { | ||
throw new Error('Cannot find lazyAssync global varible'); | ||
} | ||
if (typeof expect === 'undefined') { | ||
var expect = require('expect.js'); | ||
} | ||
(function (root) { | ||
if (typeof window === 'undefined') { | ||
require('..'); // Node | ||
} | ||
if (typeof lazyAssync === 'undefined') { | ||
throw new Error('Cannot find lazyAssync global varible'); | ||
} | ||
if (typeof root.expect === 'undefined') { | ||
root.expect = require('expect.js'); | ||
} | ||
describe('lazyAssync', function () { | ||
describe('lazyAssync function itself', function () { | ||
it('is a function', function () { | ||
expect(lazyAssync).not.to.be(undefined); | ||
expect(lazyAssync).to.be.a('function'); | ||
}); | ||
var expect = root.expect; | ||
it('has alias', function () { | ||
expect(lac).to.be.a('function'); | ||
}); | ||
describe('lazyAssync', function () { | ||
describe('lazyAssync function itself', function () { | ||
it('is a function', function () { | ||
expect(lazyAssync).not.to.be(undefined); | ||
expect(lazyAssync).to.be.a('function'); | ||
}); | ||
it('does not throw if condition is true', function () { | ||
expect(function () { | ||
lazyAssync(true); | ||
}).not.to.throwError(); | ||
}); | ||
it('has alias', function () { | ||
expect(lac).to.be.a('function'); | ||
}); | ||
it('does not evaluate function if condition is true', function () { | ||
function foo() { | ||
throw new Error('Foo has been called'); | ||
} | ||
lazyAssync(true, foo); | ||
it('does not throw if condition is true', function () { | ||
expect(function () { | ||
lazyAssync(true); | ||
}).not.to.throwError(); | ||
}); | ||
it('does not evaluate function if condition is true', function () { | ||
function foo() { | ||
throw new Error('Foo has been called'); | ||
} | ||
lazyAssync(true, foo); | ||
}); | ||
}); | ||
}); | ||
}); | ||
}(this)); |
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
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
25679
452
204
25