chai-datetime
Advanced tools
Comparing version 1.8.0 to 1.8.1
@@ -68,2 +68,8 @@ (function (plugin) { | ||
var dateWithoutTime = function (date) { | ||
return new Date(date.getFullYear(), date.getMonth(), date.getDate()); | ||
}; | ||
// assertions logic | ||
chai.datetime.equalTime = function (actual, expected) { | ||
@@ -74,2 +80,11 @@ return actual.getTime() == expected.getTime(); | ||
chai.datetime.closeToTime = function (actual, expected, deltaInSeconds) { | ||
if ( | ||
(!deltaInSeconds && deltaInSeconds !== 0) || | ||
typeof deltaInSeconds !== "number" | ||
) { | ||
throw new chai.AssertionError( | ||
"second argument of closeToTime, 'deltaInSeconds', must be a positive number" | ||
); | ||
} | ||
return ( | ||
@@ -84,5 +99,2 @@ Math.abs(actual.getTime() - expected.getTime()) < deltaInSeconds * 1000 | ||
var dateWithoutTime = function (date) { | ||
return new Date(date.getFullYear(), date.getMonth(), date.getDate()); | ||
}; | ||
@@ -126,11 +138,15 @@ chai.datetime.beforeDate = function (actual, expected) { | ||
// chainable interface | ||
chai.Assertion.addChainableMethod("equalTime", function (expected) { | ||
var actual = this._obj; | ||
var expectedFormatted = chai.datetime.formatTime(expected), | ||
actualFormatted = chai.datetime.formatTime(actual); | ||
return this.assert( | ||
chai.datetime.equalTime(expected, actual), | ||
"expected " + this._obj + " to equal " + expected, | ||
"expected " + this._obj + " to not equal " + expected, | ||
expected.toString(), | ||
actual.toString() | ||
"expected " + actualFormatted + " to equal " + expectedFormatted, | ||
"expected " + actualFormatted + " to not equal " + expectedFormatted, | ||
expectedFormatted, | ||
actualFormatted | ||
); | ||
@@ -144,28 +160,21 @@ }); | ||
var actual = this._obj; | ||
var expectedFormatted = chai.datetime.formatTime(expected), | ||
actualFormatted = chai.datetime.formatTime(this._obj); | ||
if ( | ||
(!deltaInSeconds && deltaInSeconds !== 0) || | ||
typeof deltaInSeconds !== "number" | ||
) { | ||
throw new chai.AssertionError( | ||
"second argument of closeToTime, 'deltaInSeconds', must be a number" | ||
); | ||
} | ||
return this.assert( | ||
chai.datetime.closeToTime(expected, actual, deltaInSeconds), | ||
"expected " + | ||
this._obj + | ||
actualFormatted + | ||
" to be within " + | ||
deltaInSeconds + | ||
"s of " + | ||
expected, | ||
expectedFormatted, | ||
"expected " + | ||
this._obj + | ||
actualFormatted + | ||
" to not be within " + | ||
deltaInSeconds + | ||
"s of " + | ||
expected, | ||
expected.toString(), | ||
actual.toString() | ||
expectedFormatted, | ||
expectedFormatted + ' ± ' + deltaInSeconds + 'sec', | ||
actualFormatted | ||
); | ||
@@ -175,9 +184,11 @@ }); | ||
chai.Assertion.addChainableMethod("equalDate", function (expected) { | ||
var expectedDate = chai.datetime.formatDate(expected), | ||
actualDate = chai.datetime.formatDate(this._obj); | ||
var expectedDateFormatted = chai.datetime.formatDate(expected), | ||
actualDateFormatted = chai.datetime.formatDate(this._obj); | ||
return this.assert( | ||
chai.datetime.equalDate(this._obj, expected), | ||
"expected " + actualDate + " to equal " + expectedDate, | ||
"expected " + actualDate + " to not equal " + expectedDate | ||
"expected " + actualDateFormatted + " to equal " + expectedDateFormatted, | ||
"expected " + actualDateFormatted + " to not equal " + expectedDateFormatted, | ||
expectedDateFormatted, | ||
actualDateFormatted | ||
); | ||
@@ -188,2 +199,4 @@ }); | ||
var actual = this._obj; | ||
var expectedDateFormatted = chai.datetime.formatDate(expected), | ||
actualDateFormatted = chai.datetime.formatDate(this._obj); | ||
@@ -193,9 +206,9 @@ this.assert( | ||
"expected " + | ||
chai.datetime.formatDate(actual) + | ||
actualDateFormatted + | ||
" to be before " + | ||
chai.datetime.formatDate(expected), | ||
expectedDateFormatted, | ||
"expected " + | ||
chai.datetime.formatDate(actual) + | ||
actualDateFormatted + | ||
" not to be before " + | ||
chai.datetime.formatDate(expected) | ||
expectedDateFormatted | ||
); | ||
@@ -206,2 +219,4 @@ }); | ||
var actual = this._obj; | ||
var expectedDateFormatted = chai.datetime.formatDate(expected), | ||
actualDateFormatted = chai.datetime.formatDate(this._obj); | ||
@@ -212,9 +227,9 @@ this.assert( | ||
"expected " + | ||
chai.datetime.formatDate(actual) + | ||
actualDateFormatted + | ||
" to be before or equal to " + | ||
chai.datetime.formatDate(expected), | ||
expectedDateFormatted, | ||
"expected " + | ||
chai.datetime.formatDate(actual) + | ||
actualDateFormatted + | ||
" not to be before or equal to " + | ||
chai.datetime.formatDate(expected) | ||
expectedDateFormatted | ||
); | ||
@@ -225,2 +240,4 @@ }); | ||
var actual = this._obj; | ||
var expectedDateFormatted = chai.datetime.formatDate(expected), | ||
actualDateFormatted = chai.datetime.formatDate(this._obj); | ||
@@ -230,9 +247,9 @@ this.assert( | ||
"expected " + | ||
chai.datetime.formatDate(actual) + | ||
actualDateFormatted + | ||
" to be after " + | ||
chai.datetime.formatDate(expected), | ||
expectedDateFormatted, | ||
"expected " + | ||
chai.datetime.formatDate(actual) + | ||
actualDateFormatted + | ||
" not to be after " + | ||
chai.datetime.formatDate(expected) | ||
expectedDateFormatted | ||
); | ||
@@ -243,2 +260,4 @@ }); | ||
var actual = this._obj; | ||
var expectedDateFormatted = chai.datetime.formatDate(expected), | ||
actualDateFormatted = chai.datetime.formatDate(this._obj); | ||
@@ -249,9 +268,9 @@ this.assert( | ||
"expected " + | ||
chai.datetime.formatDate(actual) + | ||
actualDateFormatted + | ||
" to be after or equal to " + | ||
chai.datetime.formatDate(expected), | ||
expectedDateFormatted, | ||
"expected " + | ||
chai.datetime.formatDate(actual) + | ||
actualDateFormatted + | ||
" not to be after or equal to " + | ||
chai.datetime.formatDate(expected) | ||
expectedDateFormatted | ||
); | ||
@@ -265,2 +284,5 @@ }); | ||
var actual = this._obj; | ||
var expectedDateFromFormatted = chai.datetime.formatDate(expectedFrom), | ||
expectedDateToFormatted = chai.datetime.formatDate(expectedTo), | ||
actualDateFormatted = chai.datetime.formatDate(this._obj); | ||
@@ -270,13 +292,13 @@ this.assert( | ||
"expected " + | ||
chai.datetime.formatDate(actual) + | ||
actualDateFormatted + | ||
" to be within " + | ||
chai.datetime.formatDate(expectedFrom) + | ||
expectedDateFromFormatted + | ||
" and " + | ||
chai.datetime.formatDate(expectedTo), | ||
expectedDateToFormatted, | ||
"expected " + | ||
chai.datetime.formatDate(actual) + | ||
actualDateFormatted + | ||
" not to be within " + | ||
chai.datetime.formatDate(expectedFrom) + | ||
expectedDateFromFormatted + | ||
" and " + | ||
chai.datetime.formatDate(expectedTo) | ||
expectedDateToFormatted | ||
); | ||
@@ -287,2 +309,4 @@ }); | ||
var actual = this._obj; | ||
var expectedFormatted = chai.datetime.formatTime(expected), | ||
actualFormatted = chai.datetime.formatTime(actual); | ||
@@ -292,9 +316,9 @@ this.assert( | ||
"expected " + | ||
chai.datetime.formatTime(actual) + | ||
actualFormatted + | ||
" to be before " + | ||
chai.datetime.formatTime(expected), | ||
expectedFormatted, | ||
"expected " + | ||
chai.datetime.formatTime(actual) + | ||
actualFormatted + | ||
" not to be before " + | ||
chai.datetime.formatTime(expected) | ||
expectedFormatted | ||
); | ||
@@ -305,2 +329,4 @@ }); | ||
var actual = this._obj; | ||
var expectedFormatted = chai.datetime.formatTime(expected), | ||
actualFormatted = chai.datetime.formatTime(actual); | ||
@@ -311,9 +337,9 @@ this.assert( | ||
"expected " + | ||
chai.datetime.formatTime(actual) + | ||
actualFormatted + | ||
" to be before or equal to " + | ||
chai.datetime.formatTime(expected), | ||
expectedFormatted, | ||
"expected " + | ||
chai.datetime.formatTime(actual) + | ||
actualFormatted + | ||
" not to be before or equal to " + | ||
chai.datetime.formatTime(expected) | ||
expectedFormatted | ||
); | ||
@@ -324,2 +350,4 @@ }); | ||
var actual = this._obj; | ||
var expectedFormatted = chai.datetime.formatTime(expected), | ||
actualFormatted = chai.datetime.formatTime(actual); | ||
@@ -329,9 +357,9 @@ this.assert( | ||
"expected " + | ||
chai.datetime.formatTime(actual) + | ||
actualFormatted + | ||
" to be after " + | ||
chai.datetime.formatTime(expected), | ||
expectedFormatted, | ||
"expected " + | ||
chai.datetime.formatTime(actual) + | ||
actualFormatted + | ||
" not to be after " + | ||
chai.datetime.formatTime(expected) | ||
expectedFormatted | ||
); | ||
@@ -342,2 +370,4 @@ }); | ||
var actual = this._obj; | ||
var expectedFormatted = chai.datetime.formatTime(expected), | ||
actualFormatted = chai.datetime.formatTime(actual); | ||
@@ -348,9 +378,9 @@ this.assert( | ||
"expected " + | ||
chai.datetime.formatTime(actual) + | ||
actualFormatted + | ||
" to be after or equal to " + | ||
chai.datetime.formatTime(expected), | ||
expectedFormatted, | ||
"expected " + | ||
chai.datetime.formatTime(actual) + | ||
actualFormatted + | ||
" not to be after or equal to " + | ||
chai.datetime.formatTime(expected) | ||
expectedFormatted | ||
); | ||
@@ -364,2 +394,5 @@ }); | ||
var actual = this._obj; | ||
var expectedFromFormatted = chai.datetime.formatTime(expectedFrom), | ||
expectedToFormatted = chai.datetime.formatTime(expectedTo), | ||
actualFormatted = chai.datetime.formatTime(actual); | ||
@@ -369,16 +402,18 @@ this.assert( | ||
"expected " + | ||
chai.datetime.formatTime(actual) + | ||
actualFormatted + | ||
" to be within " + | ||
chai.datetime.formatTime(expectedFrom) + | ||
expectedFromFormatted + | ||
" and " + | ||
chai.datetime.formatTime(expectedTo), | ||
expectedToFormatted, | ||
"expected " + | ||
chai.datetime.formatTime(actual) + | ||
actualFormatted + | ||
" not to be within " + | ||
chai.datetime.formatTime(expectedFrom) + | ||
expectedFromFormatted + | ||
" and " + | ||
chai.datetime.formatTime(expectedTo) | ||
expectedToFormatted | ||
); | ||
}); | ||
// "assert" interface | ||
// Asserts | ||
@@ -385,0 +420,0 @@ var assert = chai.assert; |
{ | ||
"name": "chai-datetime", | ||
"version": "1.8.0", | ||
"version": "1.8.1", | ||
"keywords": [ | ||
@@ -24,4 +24,4 @@ "chai", | ||
"author": { | ||
"name": "Michael Guterl", | ||
"email": "michael@diminishing.org", | ||
"name": "Mike Guterl", | ||
"email": "mike@diminishing.org", | ||
"url": "https://diminishing.org" | ||
@@ -32,3 +32,3 @@ }, | ||
"husky": "^4.2.5", | ||
"mocha": "^7.1.1", | ||
"mocha": "^10.2.0", | ||
"nodemon": "~0.6.23", | ||
@@ -35,0 +35,0 @@ "prettier": "2.0.5", |
@@ -200,3 +200,6 @@ (function (test) { | ||
}.should.fail( | ||
"expected " + test.subject + " to not equal " + test.same | ||
"expected " + | ||
chai.datetime.formatTime(test.subject) + | ||
" to not equal " + | ||
chai.datetime.formatTime(test.same) | ||
)); | ||
@@ -214,3 +217,6 @@ }); | ||
}.should.fail( | ||
"expected " + test.subject + " to equal " + test.different | ||
"expected " + | ||
chai.datetime.formatTime(test.subject) + | ||
" to equal " + | ||
chai.datetime.formatTime(test.different) | ||
)); | ||
@@ -264,5 +270,5 @@ }); | ||
"expected " + | ||
test.subject + | ||
chai.datetime.formatTime(test.subject) + | ||
" to not be within 5s of " + | ||
test.subjetPlus3seconds | ||
chai.datetime.formatTime(test.subjetPlus3seconds) | ||
)); | ||
@@ -285,5 +291,5 @@ }); | ||
"expected " + | ||
test.subject + | ||
chai.datetime.formatTime(test.subject) + | ||
" to be within 50s of " + | ||
test.different | ||
chai.datetime.formatTime(test.different) | ||
)); | ||
@@ -290,0 +296,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
55967
1441