chai-leaflet
Advanced tools
Comparing version 0.0.7 to 0.0.8
@@ -31,6 +31,8 @@ /** | ||
function deepAlmostEqual(actual, expected, delta) { | ||
function deepAlmostEqual(actual, expected, delta, error) { | ||
if (delta === undefined) { | ||
throw new Error('No delta provided'); | ||
} | ||
error = error || {}; | ||
error.message = ''; | ||
@@ -41,2 +43,7 @@ var i; | ||
if (!deepAlmostEqual(actual[i], expected[i], delta)) { | ||
error.message = ' at index ' + i; | ||
if (Array.isArray(actual[i]) || typeof actual[i] === 'object') { | ||
error.message += ': ' + actual[i] + ' should be almost equal to ' + expected[i]; | ||
} | ||
return false; | ||
@@ -51,2 +58,7 @@ } | ||
if (!deepAlmostEqual(actual[i], expected[i], delta)) { | ||
error.message = ' at key ' + i; | ||
if (Array.isArray(actual[i]) || typeof actual[i] === 'object') { | ||
error.message += ': ' + actual[i] + ' should be almost equal to ' + expected[i]; | ||
} | ||
return false; | ||
@@ -62,6 +74,7 @@ } | ||
Assertion.addMethod('deepAlmostEqual', function (expected, delta) { | ||
var error = {}; | ||
this.assert( | ||
deepAlmostEqual(this._obj, expected, delta), | ||
'expected #{act} to be almost equal to #{exp}', | ||
'expected #{act} to be not almost equal to #{exp}', | ||
deepAlmostEqual(this._obj, expected, delta, error), | ||
'expected #{act} to be almost equal to #{exp}' + error.message, | ||
'expected #{act} to be not almost equal to #{exp}' + error.message, | ||
expected, | ||
@@ -68,0 +81,0 @@ this._obj |
{ | ||
"name": "chai-leaflet", | ||
"version": "0.0.7", | ||
"version": "0.0.8", | ||
"description": "Chai assertions to use with Leaflet map apps", | ||
@@ -5,0 +5,0 @@ "main": "chai-leaflet.js", |
@@ -41,2 +41,46 @@ 'use strict'; | ||
describe('error messages', function () { | ||
var error, fn; | ||
beforeEach(function () { | ||
error = ''; | ||
fn = null; | ||
}); | ||
it('should report the right index', function () { | ||
fn = function () { | ||
[1, 2, 3, 4].should.be.deepAlmostEqual([1, 2, 3, 5], 0.1); | ||
}; | ||
fn.should.throw('expected [ 1, 2, 3, 4 ] to be almost equal to [ 1, 2, 3, 5 ] at index 3'); | ||
}); | ||
it('should display the second level if type is array/object', function () { | ||
fn = function () { | ||
[ | ||
[1, 2], | ||
[2, 3] | ||
].should.be.deepAlmostEqual([ | ||
[1, 2], | ||
[4, 4] | ||
], 0.1); | ||
}; | ||
fn.should.throw('expected [ [ 1, 2 ], [ 2, 3 ] ] to be almost equal to ' + | ||
'[ [ 1, 2 ], [ 4, 4 ] ] at index 1: 2,3 should be almost equal to 4,4'); | ||
}); | ||
it('should report the key for objects', function () { | ||
fn = function () { | ||
var obj = { | ||
foo: [1, 2], | ||
bar: [1, 2, 3] | ||
}; | ||
obj.should.be.deepAlmostEqual({ | ||
foo: [1, 2], | ||
bar: [1, 3, 4] | ||
}, 0.1); | ||
}; | ||
fn.should.throw('expected { foo: [ 1, 2 ], bar: [ 1, 2, 3 ] } to be almost equal to ' + | ||
'{ foo: [ 1, 2 ], bar: [ 1, 3, 4 ] } at key bar: 1,2,3 should be almost equal to 1,3,4'); | ||
}); | ||
}); | ||
}); | ||
@@ -43,0 +87,0 @@ |
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
10929
241