lazy-assert
Advanced tools
Comparing version 0.1.4 to 0.1.5
{ | ||
"name": "lazy-assert", | ||
"version": "0.1.4", | ||
"version": "0.1.5", | ||
"description": "An way of doing assertion for lazy people ...", | ||
@@ -5,0 +5,0 @@ "main": "src/index.js", |
var assert = require('assert'); | ||
var utils = require('./utils'); | ||
var fs = require('fs'); | ||
try { | ||
var fs = require('fs'); | ||
} | ||
catch (ex) { | ||
fs = require('./fake-fs'); | ||
} | ||
/** | ||
@@ -281,2 +287,30 @@ * @start-def: lazyAssert: {} | ||
compare: function (peekKey, actualTargetValue, expectedPreparedValue, depthOrPlugin) { | ||
var actualString = utils.trim(lazyAssert.stringify(actualTargetValue, depthOrPlugin)); | ||
var expectedString = utils.trim(lazyAssert.innerStringify(expectedPreparedValue)); | ||
// console.log('@@d'); | ||
// console.log('"' + actualString + '"'); | ||
// console.log('"' + expectedString + '"'); | ||
// console.log(actualString === expectedString); | ||
if (actualString !== expectedString) { | ||
console.warn('[WARN] peek <' + peekKey + '> did not match the expected value, the actual prepared value is : '); | ||
console.warn('[WARN] ', JSON.stringify(lazyAssert.prepareValue(actualTargetValue, depthOrPlugin), null, 2)); | ||
return false; | ||
} | ||
return true; | ||
}, | ||
assert: function (peekKey, actualTargetValue, expectedPreparedValue, depthOrPlugin) { | ||
var actualString = utils.trim(lazyAssert.stringify(actualTargetValue, depthOrPlugin)); | ||
var expectedString = utils.trim(lazyAssert.innerStringify(expectedPreparedValue, depthOrPlugin)); | ||
if (actualString !== expectedString) { | ||
console.warn('[WARN] peek <' + peekKey + '> did not match the expected value, the actual prepared value is : '); | ||
console.warn('[WARN] ', JSON.stringify(lazyAssert.prepareValue(actualTargetValue, depthOrPlugin), null, 2)); | ||
} | ||
assert.equal(actualString, expectedString, peekKey); | ||
}, | ||
newPeek: function (peekKey) { | ||
@@ -283,0 +317,0 @@ var peek = new Peek(peekKey); |
@@ -57,5 +57,5 @@ var utils = require('./utils'); | ||
if (pattern.hasOwnProperty(key)) { | ||
if (typeof subPattern === 'function') { | ||
if (typeof pattern[key] === 'function') { | ||
// match function | ||
result[key] = inner.patternFunction(object[key], key, pattern); | ||
result[key] = inner.patternFunction(object[key], key, pattern[key]); | ||
} | ||
@@ -62,0 +62,0 @@ else { |
var npath = require('path'); | ||
var fs = require('fs'); | ||
try { | ||
var fs = require('fs'); | ||
} | ||
catch (ex) { | ||
} | ||
/** | ||
@@ -106,5 +112,14 @@ * @start-def: utils: {} | ||
} | ||
} | ||
}, | ||
/** | ||
* // remove the leading/following whitespaces | ||
* @def: .trim: string => string | ||
*/ | ||
trim: function(string) { | ||
string = string || ''; | ||
return string.replace(/^\s+/, '').replace(/\s+$/, ''); | ||
}, | ||
}; | ||
module.exports = utils; |
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
386117
1
142
2300