chai-datetime
Advanced tools
Comparing version 1.5.0 to 1.6.0
@@ -1,2 +0,2 @@ | ||
(function(plugin){ | ||
(function (plugin) { | ||
if ( | ||
@@ -9,6 +9,3 @@ typeof require === "function" && | ||
module.exports = plugin; | ||
} else if ( | ||
typeof define === "function" && | ||
define.amd | ||
) { | ||
} else if (typeof define === "function" && define.amd) { | ||
// AMD | ||
@@ -22,7 +19,7 @@ define(function () { | ||
} | ||
}(function(chai, utils){ | ||
})(function (chai, utils) { | ||
chai.datetime = chai.datetime || {}; | ||
function padNumber(num, length) { | ||
var ret = '' + num; | ||
var ret = "" + num; | ||
var i = ret.length; | ||
@@ -35,3 +32,3 @@ | ||
for (i; i < length; i++) { | ||
ret = '0' + ret; | ||
ret = "0" + ret; | ||
} | ||
@@ -42,3 +39,3 @@ | ||
chai.datetime.getFormattedTimezone = function(timezoneInMinutes) { | ||
chai.datetime.getFormattedTimezone = function (timezoneInMinutes) { | ||
var tz = Math.abs(timezoneInMinutes); | ||
@@ -49,41 +46,61 @@ var hours = Math.floor(tz / 60); | ||
return (isAheadOfUtc ? '+' : '-') + | ||
padNumber(hours) + ':' + | ||
padNumber(minutes); | ||
} | ||
return ( | ||
(isAheadOfUtc ? "+" : "-") + padNumber(hours) + ":" + padNumber(minutes) | ||
); | ||
}; | ||
chai.datetime.formatDate = function(date) { | ||
chai.datetime.formatDate = function (date) { | ||
return date.toDateString(); | ||
}; | ||
chai.datetime.formatTime = function(time) { | ||
return time.toDateString() + ' ' + | ||
padNumber(time.getHours()) + ':' + | ||
padNumber(time.getMinutes()) + ':' + | ||
padNumber(time.getSeconds()) + '.' + | ||
padNumber(time.getMilliseconds(), 3) + ' (' + | ||
chai.datetime.getFormattedTimezone(time.getTimezoneOffset()) + ')'; | ||
chai.datetime.formatTime = function (time) { | ||
return ( | ||
time.toDateString() + | ||
" " + | ||
padNumber(time.getHours()) + | ||
":" + | ||
padNumber(time.getMinutes()) + | ||
":" + | ||
padNumber(time.getSeconds()) + | ||
"." + | ||
padNumber(time.getMilliseconds(), 3) + | ||
" (" + | ||
chai.datetime.getFormattedTimezone(time.getTimezoneOffset()) + | ||
")" | ||
); | ||
}; | ||
chai.datetime.equalTime = function(actual, expected) { | ||
chai.datetime.equalTime = function (actual, expected) { | ||
return actual.getTime() == expected.getTime(); | ||
}; | ||
chai.datetime.equalDate = function(actual, expected) { | ||
chai.datetime.closeToTime = function (actual, expected, deltaInSeconds) { | ||
return ( | ||
Math.abs(actual.getTime() - expected.getTime()) < deltaInSeconds * 1000 | ||
); | ||
}; | ||
chai.datetime.equalDate = function (actual, expected) { | ||
return actual.toDateString() === expected.toDateString(); | ||
}; | ||
var dateWithoutTime = function(date) { | ||
var dateWithoutTime = function (date) { | ||
return new Date(date.getFullYear(), date.getMonth(), date.getDate()); | ||
} | ||
}; | ||
chai.datetime.beforeDate = function(actual, expected) { | ||
return chai.datetime.beforeTime(dateWithoutTime(actual), dateWithoutTime(expected)); | ||
chai.datetime.beforeDate = function (actual, expected) { | ||
return chai.datetime.beforeTime( | ||
dateWithoutTime(actual), | ||
dateWithoutTime(expected) | ||
); | ||
}; | ||
chai.datetime.afterDate = function(actual, expected) { | ||
return chai.datetime.afterTime(dateWithoutTime(actual), dateWithoutTime(expected)); | ||
chai.datetime.afterDate = function (actual, expected) { | ||
return chai.datetime.afterTime( | ||
dateWithoutTime(actual), | ||
dateWithoutTime(expected) | ||
); | ||
}; | ||
chai.datetime.withinDate = function(actual, expectedFrom, expectedTo) { | ||
chai.datetime.withinDate = function (actual, expectedFrom, expectedTo) { | ||
return chai.datetime.withinTime( | ||
@@ -96,15 +113,18 @@ dateWithoutTime(actual), | ||
chai.datetime.beforeTime = function(actual, expected) { | ||
chai.datetime.beforeTime = function (actual, expected) { | ||
return actual.getTime() < expected.getTime(); | ||
}; | ||
chai.datetime.afterTime = function(actual, expected) { | ||
chai.datetime.afterTime = function (actual, expected) { | ||
return actual.getTime() > expected.getTime(); | ||
}; | ||
chai.datetime.withinTime = function(actual, expectedFrom, expectedTo) { | ||
return actual.getTime() >= expectedFrom.getTime() && actual.getTime() <= expectedTo.getTime(); | ||
chai.datetime.withinTime = function (actual, expectedFrom, expectedTo) { | ||
return ( | ||
actual.getTime() >= expectedFrom.getTime() && | ||
actual.getTime() <= expectedTo.getTime() | ||
); | ||
}; | ||
chai.Assertion.addChainableMethod('equalTime', function(expected) { | ||
chai.Assertion.addChainableMethod("equalTime", function (expected) { | ||
var actual = this._obj; | ||
@@ -114,4 +134,4 @@ | ||
chai.datetime.equalTime(expected, actual), | ||
'expected ' + this._obj + ' to equal ' + expected, | ||
'expected ' + this._obj + ' to not equal ' + expected, | ||
"expected " + this._obj + " to equal " + expected, | ||
"expected " + this._obj + " to not equal " + expected, | ||
expected.toString(), | ||
@@ -122,14 +142,48 @@ actual.toString() | ||
chai.Assertion.addChainableMethod('equalDate', function(expected) { | ||
var expectedDate = chai.datetime.formatDate(expected), | ||
actualDate = chai.datetime.formatDate(this._obj); | ||
chai.Assertion.addChainableMethod("closeToTime", function ( | ||
expected, | ||
deltaInSeconds | ||
) { | ||
var actual = 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 + | ||
" to be within " + | ||
deltaInSeconds + | ||
"s of " + | ||
expected, | ||
"expected " + | ||
this._obj + | ||
" to not be within " + | ||
deltaInSeconds + | ||
"s of " + | ||
expected, | ||
expected.toString(), | ||
actual.toString() | ||
); | ||
}); | ||
chai.Assertion.addChainableMethod("equalDate", function (expected) { | ||
var expectedDate = chai.datetime.formatDate(expected), | ||
actualDate = 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 " + actualDate + " to equal " + expectedDate, | ||
"expected " + actualDate + " to not equal " + expectedDate | ||
); | ||
}); | ||
chai.Assertion.addChainableMethod('beforeDate', function(expected) { | ||
chai.Assertion.addChainableMethod("beforeDate", function (expected) { | ||
var actual = this._obj; | ||
@@ -139,8 +193,14 @@ | ||
chai.datetime.beforeDate(actual, expected), | ||
'expected ' + chai.datetime.formatDate(actual) + ' to be before ' + chai.datetime.formatDate(expected), | ||
'expected ' + chai.datetime.formatDate(actual) + ' not to be before ' + chai.datetime.formatDate(expected) | ||
"expected " + | ||
chai.datetime.formatDate(actual) + | ||
" to be before " + | ||
chai.datetime.formatDate(expected), | ||
"expected " + | ||
chai.datetime.formatDate(actual) + | ||
" not to be before " + | ||
chai.datetime.formatDate(expected) | ||
); | ||
}); | ||
chai.Assertion.addChainableMethod('afterDate', function(expected) { | ||
chai.Assertion.addChainableMethod("afterDate", function (expected) { | ||
var actual = this._obj; | ||
@@ -150,8 +210,17 @@ | ||
chai.datetime.afterDate(actual, expected), | ||
'expected ' + chai.datetime.formatDate(actual) + ' to be after ' + chai.datetime.formatDate(expected), | ||
'expected ' + chai.datetime.formatDate(actual) + ' not to be after ' + chai.datetime.formatDate(expected) | ||
"expected " + | ||
chai.datetime.formatDate(actual) + | ||
" to be after " + | ||
chai.datetime.formatDate(expected), | ||
"expected " + | ||
chai.datetime.formatDate(actual) + | ||
" not to be after " + | ||
chai.datetime.formatDate(expected) | ||
); | ||
}); | ||
chai.Assertion.addChainableMethod('withinDate', function(expectedFrom, expectedTo) { | ||
chai.Assertion.addChainableMethod("withinDate", function ( | ||
expectedFrom, | ||
expectedTo | ||
) { | ||
var actual = this._obj; | ||
@@ -161,8 +230,18 @@ | ||
chai.datetime.withinDate(actual, expectedFrom, expectedTo), | ||
'expected ' + chai.datetime.formatDate(actual) + ' to be within ' + chai.datetime.formatDate(expectedFrom) + ' and ' + chai.datetime.formatDate(expectedTo), | ||
'expected ' + chai.datetime.formatDate(actual) + ' not to be within ' + chai.datetime.formatDate(expectedFrom) + ' and ' + chai.datetime.formatDate(expectedTo) | ||
"expected " + | ||
chai.datetime.formatDate(actual) + | ||
" to be within " + | ||
chai.datetime.formatDate(expectedFrom) + | ||
" and " + | ||
chai.datetime.formatDate(expectedTo), | ||
"expected " + | ||
chai.datetime.formatDate(actual) + | ||
" not to be within " + | ||
chai.datetime.formatDate(expectedFrom) + | ||
" and " + | ||
chai.datetime.formatDate(expectedTo) | ||
); | ||
}); | ||
chai.Assertion.addChainableMethod('beforeTime', function(expected) { | ||
chai.Assertion.addChainableMethod("beforeTime", function (expected) { | ||
var actual = this._obj; | ||
@@ -172,8 +251,14 @@ | ||
chai.datetime.beforeTime(actual, expected), | ||
'expected ' + chai.datetime.formatTime(actual) + ' to be before ' + chai.datetime.formatTime(expected), | ||
'expected ' + chai.datetime.formatTime(actual) + ' not to be before ' + chai.datetime.formatTime(expected) | ||
"expected " + | ||
chai.datetime.formatTime(actual) + | ||
" to be before " + | ||
chai.datetime.formatTime(expected), | ||
"expected " + | ||
chai.datetime.formatTime(actual) + | ||
" not to be before " + | ||
chai.datetime.formatTime(expected) | ||
); | ||
}); | ||
chai.Assertion.addChainableMethod('afterTime', function(expected) { | ||
chai.Assertion.addChainableMethod("afterTime", function (expected) { | ||
var actual = this._obj; | ||
@@ -183,8 +268,17 @@ | ||
chai.datetime.afterTime(actual, expected), | ||
'expected ' + chai.datetime.formatTime(actual) + ' to be after ' + chai.datetime.formatTime(expected), | ||
'expected ' + chai.datetime.formatTime(actual) + ' not to be after ' + chai.datetime.formatTime(expected) | ||
"expected " + | ||
chai.datetime.formatTime(actual) + | ||
" to be after " + | ||
chai.datetime.formatTime(expected), | ||
"expected " + | ||
chai.datetime.formatTime(actual) + | ||
" not to be after " + | ||
chai.datetime.formatTime(expected) | ||
); | ||
}); | ||
chai.Assertion.addChainableMethod('withinTime', function(expectedFrom, expectedTo) { | ||
chai.Assertion.addChainableMethod("withinTime", function ( | ||
expectedFrom, | ||
expectedTo | ||
) { | ||
var actual = this._obj; | ||
@@ -194,4 +288,14 @@ | ||
chai.datetime.withinTime(actual, expectedFrom, expectedTo), | ||
'expected ' + chai.datetime.formatTime(actual) + ' to be within ' + chai.datetime.formatTime(expectedFrom) + ' and ' + chai.datetime.formatTime(expectedTo), | ||
'expected ' + chai.datetime.formatTime(actual) + ' not to be within ' + chai.datetime.formatTime(expectedFrom) + ' and ' + chai.datetime.formatTime(expectedTo) | ||
"expected " + | ||
chai.datetime.formatTime(actual) + | ||
" to be within " + | ||
chai.datetime.formatTime(expectedFrom) + | ||
" and " + | ||
chai.datetime.formatTime(expectedTo), | ||
"expected " + | ||
chai.datetime.formatTime(actual) + | ||
" not to be within " + | ||
chai.datetime.formatTime(expectedFrom) + | ||
" and " + | ||
chai.datetime.formatTime(expectedTo) | ||
); | ||
@@ -203,65 +307,65 @@ }); | ||
assert.equalDate = function(val, exp, msg) { | ||
assert.equalDate = function (val, exp, msg) { | ||
new chai.Assertion(val, msg).to.be.equalDate(exp); | ||
}; | ||
assert.notEqualDate = function(val, exp, msg) { | ||
assert.notEqualDate = function (val, exp, msg) { | ||
new chai.Assertion(val, msg).to.not.be.equalDate(exp); | ||
}; | ||
assert.beforeDate = function(val, exp, msg) { | ||
assert.beforeDate = function (val, exp, msg) { | ||
new chai.Assertion(val, msg).to.be.beforeDate(exp); | ||
}; | ||
assert.notBeforeDate = function(val, exp, msg) { | ||
assert.notBeforeDate = function (val, exp, msg) { | ||
new chai.Assertion(val, msg).to.not.be.beforeDate(exp); | ||
}; | ||
assert.afterDate = function(val, exp, msg) { | ||
assert.afterDate = function (val, exp, msg) { | ||
new chai.Assertion(val, msg).to.be.afterDate(exp); | ||
}; | ||
assert.notAfterDate = function(val, exp, msg) { | ||
assert.notAfterDate = function (val, exp, msg) { | ||
new chai.Assertion(val, msg).not.to.be.afterDate(exp); | ||
}; | ||
assert.withinDate = function(val, expFrom, expTo, msg) { | ||
assert.withinDate = function (val, expFrom, expTo, msg) { | ||
new chai.Assertion(val, msg).to.be.withinDate(expFrom, expTo); | ||
}; | ||
assert.notWithinDate = function(val, expFrom, expTo, msg) { | ||
assert.notWithinDate = function (val, expFrom, expTo, msg) { | ||
new chai.Assertion(val, msg).not.to.be.withinDate(expFrom, expTo); | ||
}; | ||
assert.equalTime = function(val, exp, msg) { | ||
assert.equalTime = function (val, exp, msg) { | ||
new chai.Assertion(val, msg).to.be.equalTime(exp); | ||
}; | ||
assert.notEqualTime = function(val, exp, msg) { | ||
assert.notEqualTime = function (val, exp, msg) { | ||
new chai.Assertion(val, msg).to.not.be.equalTime(exp); | ||
}; | ||
assert.beforeTime = function(val, exp, msg) { | ||
assert.beforeTime = function (val, exp, msg) { | ||
new chai.Assertion(val, msg).to.be.beforeTime(exp); | ||
}; | ||
assert.notBeforeTime = function(val, exp, msg) { | ||
assert.notBeforeTime = function (val, exp, msg) { | ||
new chai.Assertion(val, msg).not.to.be.beforeTime(exp); | ||
}; | ||
assert.afterTime = function(val, exp, msg) { | ||
assert.afterTime = function (val, exp, msg) { | ||
new chai.Assertion(val, msg).to.be.afterTime(exp); | ||
}; | ||
assert.notAfterTime = function(val, exp, msg) { | ||
assert.notAfterTime = function (val, exp, msg) { | ||
new chai.Assertion(val, msg).to.not.be.afterTime(exp); | ||
}; | ||
assert.withinTime = function(val, expFrom, expTo, msg) { | ||
assert.withinTime = function (val, expFrom, expTo, msg) { | ||
new chai.Assertion(val, msg).to.be.withinTime(expFrom, expTo); | ||
}; | ||
assert.notWithinTime = function(val, expFrom, expTo, msg) { | ||
assert.notWithinTime = function (val, expFrom, expTo, msg) { | ||
new chai.Assertion(val, msg).not.to.be.withinTime(expFrom, expTo); | ||
}; | ||
})); | ||
}); |
{ | ||
"name": "chai-datetime", | ||
"version": "1.5.0", | ||
"keywords": ["chai", "chai-plugin", "objects", "date", "time", "browser", "testing", "jasmine"], | ||
"version": "1.6.0", | ||
"keywords": [ | ||
"chai", | ||
"chai-plugin", | ||
"objects", | ||
"date", | ||
"time", | ||
"browser", | ||
"testing", | ||
"jasmine" | ||
], | ||
"description": "date / time comparison matchers for chai", | ||
"main": "chai-datetime.js", | ||
"scripts": { | ||
"test": "./node_modules/.bin/mocha --recursive -C", | ||
"testwatch": "./node_modules/.bin/nodemon -L -d 0 -w . --exec make test", | ||
"clean": "rm -rf node_modules", | ||
"dev": "npm run clean && npm install && npm run testwatch" | ||
"test": "mocha" | ||
}, | ||
"repository": { | ||
"type": "git", | ||
"url": "git://github.com/gaslight/chai-datetime.git" | ||
"url": "git://github.com/mguterl/chai-datetime.git" | ||
}, | ||
@@ -20,12 +26,20 @@ "author": { | ||
"email": "michael@diminishing.org", | ||
"url": "http://diminishing.org" | ||
"url": "https://diminishing.org" | ||
}, | ||
"license": "MIT", | ||
"devDependencies": { | ||
"mocha": "~1.6.0", | ||
"nodemon": "~0.6.23" | ||
"husky": "^4.2.5", | ||
"mocha": "^7.1.1", | ||
"nodemon": "~0.6.23", | ||
"prettier": "2.0.5", | ||
"pretty-quick": "^2.0.1" | ||
}, | ||
"dependencies": { | ||
"chai": ">1.9.0" | ||
}, | ||
"husky": { | ||
"hooks": { | ||
"pre-commit": "pretty-quick --staged" | ||
} | ||
} | ||
} |
@@ -6,2 +6,3 @@ # chai-datetime | ||
[![npm version](https://badge.fury.io/js/chai-datetime.svg)](https://badge.fury.io/js/chai-datetime) | ||
[![Build Status](https://travis-ci.org/mguterl/chai-datetime.png?branch=master)](https://travis-ci.org/mguterl/chai-datetime) | ||
@@ -51,2 +52,3 @@ | ||
* equalTime | ||
* closeToTime (with a configurable delta in seconds) | ||
* beforeTime | ||
@@ -53,0 +55,0 @@ * afterTime |
739
test/test.js
@@ -1,13 +0,13 @@ | ||
(function(test){ | ||
(function (test) { | ||
if ( | ||
typeof require === "function" | ||
&& typeof exports === "object" | ||
&& typeof module === "object" | ||
typeof require === "function" && | ||
typeof exports === "object" && | ||
typeof module === "object" | ||
) { | ||
// NodeJS | ||
(function(){ | ||
var chai = require('chai'); | ||
(function () { | ||
var chai = require("chai"); | ||
chai.config.includeStack = true; | ||
test(chai, true); | ||
}()); | ||
})(); | ||
} else { | ||
@@ -17,4 +17,3 @@ // Other environment (usually <script> tag): plug in to global chai instance directly. | ||
} | ||
}(function(chai, testingServer){ | ||
})(function (chai, testingServer) { | ||
var should = chai.should(); | ||
@@ -24,3 +23,3 @@ var assert = chai.assert; | ||
if (testingServer) { | ||
var datetime = require('../chai-datetime'); | ||
var datetime = require("../chai-datetime"); | ||
chai.use(datetime); | ||
@@ -32,6 +31,6 @@ } | ||
chai.Assertion.addMethod('fail', function (message) { | ||
chai.Assertion.addMethod("fail", function (message) { | ||
var obj = this._obj; | ||
new chai.Assertion(obj).is.a('function'); | ||
new chai.Assertion(obj).is.a("function"); | ||
@@ -42,19 +41,24 @@ try { | ||
this.assert( | ||
err instanceof chai.AssertionError | ||
, 'expected #{this} to fail, but it threw ' + inspect(err)); | ||
err instanceof chai.AssertionError, | ||
"expected #{this} to fail, but it threw " + inspect(err) | ||
); | ||
this.assert( | ||
err.message === message | ||
, 'expected #{this} to fail with ' + inspect(message) + ', but got ' + inspect(err.message)); | ||
err.message === message, | ||
"expected #{this} to fail with " + | ||
inspect(message) + | ||
", but got " + | ||
inspect(err.message) | ||
); | ||
return; | ||
} | ||
this.assert(false, 'expected #{this} to fail'); | ||
this.assert(false, "expected #{this} to fail"); | ||
}); | ||
}); | ||
describe('chai-datetime', function() { | ||
describe('helpers', function() { | ||
describe('afterDate', function() { | ||
describe('when given two identical date objects', function() { | ||
beforeEach(function() { | ||
describe("chai-datetime", function () { | ||
describe("helpers", function () { | ||
describe("afterDate", function () { | ||
describe("when given two identical date objects", function () { | ||
beforeEach(function () { | ||
this.actual = new Date(2013, 3, 30); | ||
@@ -64,7 +68,9 @@ this.expected = new Date(2013, 3, 30); | ||
it('returns false', function() { | ||
chai.datetime.afterDate(this.actual, this.expected).should.be.eq(false) | ||
it("returns false", function () { | ||
chai.datetime | ||
.afterDate(this.actual, this.expected) | ||
.should.be.eq(false); | ||
}); | ||
it('should not be affected by time zones', function() { | ||
it("should not be affected by time zones", function () { | ||
var midnight = new Date(2014, 0, 1, 0); | ||
@@ -76,4 +82,4 @@ var endOfDay = new Date(2014, 0, 1, 23); | ||
describe('when given the actual is before the expected', function() { | ||
beforeEach(function() { | ||
describe("when given the actual is before the expected", function () { | ||
beforeEach(function () { | ||
this.actual = new Date(2014, 0, 31); | ||
@@ -83,9 +89,11 @@ this.expected = new Date(2014, 11, 1); | ||
it('returns false', function() { | ||
chai.datetime.afterDate(this.actual, this.expected).should.be.eq(false) | ||
it("returns false", function () { | ||
chai.datetime | ||
.afterDate(this.actual, this.expected) | ||
.should.be.eq(false); | ||
}); | ||
}); | ||
describe('when given the actual is after the expected', function() { | ||
beforeEach(function() { | ||
describe("when given the actual is after the expected", function () { | ||
beforeEach(function () { | ||
this.actual = new Date(2013, 3, 30); | ||
@@ -95,10 +103,12 @@ this.expected = new Date(2013, 3, 29); | ||
it('returns true', function() { | ||
chai.datetime.afterDate(this.actual, this.expected).should.be.eq(true) | ||
it("returns true", function () { | ||
chai.datetime | ||
.afterDate(this.actual, this.expected) | ||
.should.be.eq(true); | ||
}); | ||
}); | ||
describe('when the year differs', function() { | ||
describe("when the year differs", function () { | ||
// BUG: https://github.com/gaslight/chai-datetime/issues/13 | ||
beforeEach(function() { | ||
beforeEach(function () { | ||
this.actual = new Date(2014, 0, 2); | ||
@@ -108,4 +118,6 @@ this.expected = new Date(2013, 0, 2); | ||
it('returns true', function() { | ||
chai.datetime.afterDate(this.actual, this.expected).should.be.eq(true) | ||
it("returns true", function () { | ||
chai.datetime | ||
.afterDate(this.actual, this.expected) | ||
.should.be.eq(true); | ||
}); | ||
@@ -115,5 +127,5 @@ }); | ||
describe('beforeDate', function() { | ||
describe('when given two identical date objects', function() { | ||
beforeEach(function() { | ||
describe("beforeDate", function () { | ||
describe("when given two identical date objects", function () { | ||
beforeEach(function () { | ||
this.actual = new Date(2013, 3, 30); | ||
@@ -123,7 +135,9 @@ this.expected = new Date(2013, 3, 30); | ||
it('returns false', function() { | ||
chai.datetime.beforeDate(this.actual, this.expected).should.be.eq(false) | ||
it("returns false", function () { | ||
chai.datetime | ||
.beforeDate(this.actual, this.expected) | ||
.should.be.eq(false); | ||
}); | ||
it('should not be affected by time zones', function() { | ||
it("should not be affected by time zones", function () { | ||
var midnight = new Date(2014, 0, 1, 0); | ||
@@ -135,4 +149,4 @@ var endOfDay = new Date(2014, 0, 1, 23); | ||
describe('when given the actual is before the expected', function() { | ||
beforeEach(function() { | ||
describe("when given the actual is before the expected", function () { | ||
beforeEach(function () { | ||
this.actual = new Date(2013, 3, 29); | ||
@@ -142,9 +156,11 @@ this.expected = new Date(2013, 3, 30); | ||
it('returns true', function() { | ||
chai.datetime.beforeDate(this.actual, this.expected).should.be.eq(true) | ||
it("returns true", function () { | ||
chai.datetime | ||
.beforeDate(this.actual, this.expected) | ||
.should.be.eq(true); | ||
}); | ||
}); | ||
describe('when given the actual is after the expected', function() { | ||
beforeEach(function() { | ||
describe("when given the actual is after the expected", function () { | ||
beforeEach(function () { | ||
this.actual = new Date(2048, 0, 1); | ||
@@ -154,10 +170,12 @@ this.expected = new Date(2014, 11, 31); | ||
it('returns false', function() { | ||
chai.datetime.beforeDate(this.actual, this.expected).should.be.eq(false) | ||
it("returns false", function () { | ||
chai.datetime | ||
.beforeDate(this.actual, this.expected) | ||
.should.be.eq(false); | ||
}); | ||
}); | ||
describe('when the year differs', function() { | ||
describe("when the year differs", function () { | ||
// BUG: https://github.com/gaslight/chai-datetime/issues/13 | ||
beforeEach(function() { | ||
beforeEach(function () { | ||
this.actual = new Date(2013, 0, 2); | ||
@@ -167,4 +185,6 @@ this.expected = new Date(2014, 0, 2); | ||
it('returns true', function() { | ||
chai.datetime.beforeDate(this.actual, this.expected).should.be.eq(true) | ||
it("returns true", function () { | ||
chai.datetime | ||
.beforeDate(this.actual, this.expected) | ||
.should.be.eq(true); | ||
}); | ||
@@ -175,5 +195,5 @@ }); | ||
describe('matchers', function() { | ||
describe('equalTime', function() { | ||
beforeEach(function() { | ||
describe("matchers", function () { | ||
describe("equalTime", function () { | ||
beforeEach(function () { | ||
this.subject = new Date(2013, 4, 30, 16, 5); | ||
@@ -184,16 +204,16 @@ this.same = new Date(2013, 4, 30, 16, 5); | ||
describe('when given two date objects with the same values', function() { | ||
it('passes', function() { | ||
describe("when given two date objects with the same values", function () { | ||
it("passes", function () { | ||
this.subject.should.be.equalTime(this.same); | ||
}); | ||
describe('when negated', function() { | ||
it('fails', function() { | ||
describe("when negated", function () { | ||
it("fails", function () { | ||
var test = this; | ||
(function() { | ||
(function () { | ||
test.subject.should.not.be.equalTime(test.same); | ||
}).should.fail( | ||
'expected ' + test.subject + ' to not equal ' + test.same | ||
); | ||
}.should.fail( | ||
"expected " + test.subject + " to not equal " + test.same | ||
)); | ||
}); | ||
@@ -203,15 +223,15 @@ }); | ||
describe('when given two date objects with different values', function() { | ||
it('fails', function() { | ||
describe("when given two date objects with different values", function () { | ||
it("fails", function () { | ||
var test = this; | ||
(function() { | ||
(function () { | ||
test.subject.should.be.equalTime(test.different); | ||
}).should.fail( | ||
'expected ' + test.subject + ' to equal ' + test.different | ||
); | ||
}.should.fail( | ||
"expected " + test.subject + " to equal " + test.different | ||
)); | ||
}); | ||
describe('when negated', function() { | ||
it('passes', function() { | ||
describe("when negated", function () { | ||
it("passes", function () { | ||
this.subject.should.not.be.equalTime(this.different); | ||
@@ -221,7 +241,80 @@ }); | ||
}); | ||
}); | ||
describe("closeToTime", function () { | ||
beforeEach(function () { | ||
this.subject = new Date(2013, 4, 30, 16, 5, 16, 323); | ||
this.subjetPlus200Milliseconds = new Date( | ||
2013, | ||
4, | ||
30, | ||
16, | ||
5, | ||
16, | ||
523 | ||
); | ||
this.subjetPlus3seconds = new Date(2013, 4, 30, 16, 5, 19, 323); | ||
this.different = new Date(2013, 4, 30, 18, 6); | ||
}); | ||
describe("when given two date objects within the configured delta", function () { | ||
const deltaInSeconds = 5; | ||
it("passes", function () { | ||
this.subject.should.be.closeToTime( | ||
this.subjetPlus3seconds, | ||
deltaInSeconds | ||
); | ||
}); | ||
describe("when negated", function () { | ||
it("fails", function () { | ||
var test = this; | ||
(function () { | ||
test.subject.should.not.be.closeToTime( | ||
test.subjetPlus3seconds, | ||
deltaInSeconds | ||
); | ||
}.should.fail( | ||
"expected " + | ||
test.subject + | ||
" to not be within 5s of " + | ||
test.subjetPlus3seconds | ||
)); | ||
}); | ||
}); | ||
}); | ||
describe("when given two date objects with values not within configured delta", function () { | ||
const deltaInSeconds = 50; | ||
it("fails", function () { | ||
var test = this; | ||
(function () { | ||
test.subject.should.be.closeToTime( | ||
test.different, | ||
deltaInSeconds | ||
); | ||
}.should.fail( | ||
"expected " + | ||
test.subject + | ||
" to be within 50s of " + | ||
test.different | ||
)); | ||
}); | ||
describe("when negated", function () { | ||
it("passes", function () { | ||
this.subject.should.not.be.closeToTime( | ||
this.different, | ||
deltaInSeconds | ||
); | ||
}); | ||
}); | ||
}); | ||
}); | ||
describe('equalDate', function() { | ||
beforeEach(function() { | ||
describe("equalDate", function () { | ||
beforeEach(function () { | ||
this.subject = new Date(2013, 4, 30, 16, 5); | ||
@@ -232,16 +325,16 @@ this.same = new Date(2013, 4, 30, 17); | ||
describe('when given two date objects with the date values', function() { | ||
it('passes', function() { | ||
describe("when given two date objects with the date values", function () { | ||
it("passes", function () { | ||
this.subject.should.be.equalDate(this.same); | ||
}); | ||
describe('when negated', function() { | ||
it('fails', function() { | ||
describe("when negated", function () { | ||
it("fails", function () { | ||
var test = this; | ||
(function() { | ||
(function () { | ||
test.subject.should.not.be.equalDate(test.same); | ||
}).should.fail( | ||
'expected Thu May 30 2013 to not equal Thu May 30 2013' | ||
); | ||
}.should.fail( | ||
"expected Thu May 30 2013 to not equal Thu May 30 2013" | ||
)); | ||
}); | ||
@@ -251,15 +344,13 @@ }); | ||
describe('when given two date objects with different date values', function() { | ||
it('fails', function() { | ||
describe("when given two date objects with different date values", function () { | ||
it("fails", function () { | ||
var test = this; | ||
(function() { | ||
(function () { | ||
test.subject.should.be.equalDate(test.different); | ||
}).should.fail( | ||
'expected Thu May 30 2013 to equal Fri May 31 2013' | ||
); | ||
}.should.fail("expected Thu May 30 2013 to equal Fri May 31 2013")); | ||
}); | ||
describe('when negated', function() { | ||
it('passes', function() { | ||
describe("when negated", function () { | ||
it("passes", function () { | ||
this.subject.should.not.be.equalDate(this.different); | ||
@@ -269,26 +360,25 @@ }); | ||
}); | ||
}); | ||
}); | ||
describe('beforeDate', function() { | ||
describe('when given two different date objects', function() { | ||
beforeEach(function() { | ||
this.d1 = new Date(2013, 4, 30) | ||
this.d2 = new Date(2013, 4, 31) | ||
describe("beforeDate", function () { | ||
describe("when given two different date objects", function () { | ||
beforeEach(function () { | ||
this.d1 = new Date(2013, 4, 30); | ||
this.d2 = new Date(2013, 4, 31); | ||
}); | ||
it('passes', function() { | ||
it("passes", function () { | ||
this.d1.should.be.beforeDate(this.d2); | ||
}); | ||
describe('when negated', function() { | ||
it('fails', function() { | ||
describe("when negated", function () { | ||
it("fails", function () { | ||
var test = this; | ||
(function() { | ||
(function () { | ||
test.d1.should.not.be.beforeDate(test.d2); | ||
}).should.fail( | ||
'expected Thu May 30 2013 not to be before Fri May 31 2013' | ||
); | ||
}.should.fail( | ||
"expected Thu May 30 2013 not to be before Fri May 31 2013" | ||
)); | ||
}); | ||
@@ -298,20 +388,20 @@ }); | ||
describe('when given two identical date objects', function() { | ||
beforeEach(function() { | ||
this.d1 = new Date(2013, 4, 30) | ||
this.d2 = new Date(2013, 4, 30) | ||
describe("when given two identical date objects", function () { | ||
beforeEach(function () { | ||
this.d1 = new Date(2013, 4, 30); | ||
this.d2 = new Date(2013, 4, 30); | ||
}); | ||
it('fails', function() { | ||
it("fails", function () { | ||
var test = this; | ||
(function() { | ||
(function () { | ||
test.d1.should.be.beforeDate(test.d2); | ||
}).should.fail( | ||
'expected Thu May 30 2013 to be before Thu May 30 2013' | ||
); | ||
}.should.fail( | ||
"expected Thu May 30 2013 to be before Thu May 30 2013" | ||
)); | ||
}); | ||
describe('when negated', function() { | ||
it('passes', function() { | ||
describe("when negated", function () { | ||
it("passes", function () { | ||
this.d1.should.not.be.beforeDate(this.d2); | ||
@@ -322,20 +412,20 @@ }); | ||
describe('when given two identical dates but different times', function() { | ||
beforeEach(function() { | ||
this.d1 = new Date(2013, 4, 30, 17) | ||
this.d2 = new Date(2013, 4, 30, 18) | ||
describe("when given two identical dates but different times", function () { | ||
beforeEach(function () { | ||
this.d1 = new Date(2013, 4, 30, 17); | ||
this.d2 = new Date(2013, 4, 30, 18); | ||
}); | ||
it('fails', function() { | ||
it("fails", function () { | ||
var test = this; | ||
(function() { | ||
(function () { | ||
test.d1.should.be.beforeDate(test.d2); | ||
}).should.fail( | ||
'expected Thu May 30 2013 to be before Thu May 30 2013' | ||
); | ||
}.should.fail( | ||
"expected Thu May 30 2013 to be before Thu May 30 2013" | ||
)); | ||
}); | ||
describe('when negated', function() { | ||
it('passes', function() { | ||
describe("when negated", function () { | ||
it("passes", function () { | ||
this.d1.should.not.be.beforeDate(this.d2); | ||
@@ -347,5 +437,5 @@ }); | ||
describe('afterDate', function() { | ||
describe('when given two different date objects', function() { | ||
beforeEach(function() { | ||
describe("afterDate", function () { | ||
describe("when given two different date objects", function () { | ||
beforeEach(function () { | ||
this.d1 = new Date(2013, 4, 31); | ||
@@ -355,15 +445,15 @@ this.d2 = new Date(2013, 4, 30); | ||
it('passes', function() { | ||
it("passes", function () { | ||
this.d1.should.be.afterDate(this.d2); | ||
}); | ||
describe('when negated', function() { | ||
it('fails', function() { | ||
describe("when negated", function () { | ||
it("fails", function () { | ||
var test = this; | ||
(function() { | ||
(function () { | ||
test.d1.should.not.be.afterDate(test.d2); | ||
}).should.fail( | ||
'expected Fri May 31 2013 not to be after Thu May 30 2013' | ||
); | ||
}.should.fail( | ||
"expected Fri May 31 2013 not to be after Thu May 30 2013" | ||
)); | ||
}); | ||
@@ -373,4 +463,4 @@ }); | ||
describe('when given two identical date objects', function() { | ||
beforeEach(function() { | ||
describe("when given two identical date objects", function () { | ||
beforeEach(function () { | ||
this.d1 = new Date(2013, 4, 30); | ||
@@ -380,21 +470,21 @@ this.d2 = new Date(2013, 4, 30); | ||
it('fails', function() { | ||
it("fails", function () { | ||
var test = this; | ||
(function() { | ||
(function () { | ||
test.d1.should.be.afterDate(test.d2); | ||
}).should.fail( | ||
'expected Thu May 30 2013 to be after Thu May 30 2013' | ||
); | ||
}.should.fail( | ||
"expected Thu May 30 2013 to be after Thu May 30 2013" | ||
)); | ||
}); | ||
describe('when negated', function() { | ||
it('passes', function() { | ||
describe("when negated", function () { | ||
it("passes", function () { | ||
this.d1.should.not.be.afterDate(this.d2); | ||
}); | ||
}); | ||
}) | ||
}); | ||
describe('when given two identical date objects with different times', function() { | ||
beforeEach(function() { | ||
describe("when given two identical date objects with different times", function () { | ||
beforeEach(function () { | ||
this.d1 = new Date(2013, 4, 30, 17); | ||
@@ -404,23 +494,23 @@ this.d2 = new Date(2013, 4, 30, 16); | ||
it('fails', function() { | ||
it("fails", function () { | ||
var test = this; | ||
(function() { | ||
(function () { | ||
test.d1.should.be.afterDate(test.d2); | ||
}).should.fail( | ||
'expected Thu May 30 2013 to be after Thu May 30 2013' | ||
); | ||
}.should.fail( | ||
"expected Thu May 30 2013 to be after Thu May 30 2013" | ||
)); | ||
}); | ||
describe('when negated', function() { | ||
it('passes', function() { | ||
describe("when negated", function () { | ||
it("passes", function () { | ||
this.d1.should.not.be.afterDate(this.d2); | ||
}); | ||
}); | ||
}) | ||
}); | ||
}); | ||
describe('withinDate', function() { | ||
describe('when given a date between two dates', function() { | ||
beforeEach(function() { | ||
describe("withinDate", function () { | ||
describe("when given a date between two dates", function () { | ||
beforeEach(function () { | ||
this.d1 = new Date(2013, 4, 30); | ||
@@ -431,15 +521,15 @@ this.d2 = new Date(2013, 4, 29); | ||
it('passes', function() { | ||
it("passes", function () { | ||
this.d1.should.be.withinDate(this.d2, this.d3); | ||
}); | ||
describe('when negated', function() { | ||
it('fails', function() { | ||
describe("when negated", function () { | ||
it("fails", function () { | ||
var test = this; | ||
(function() { | ||
(function () { | ||
test.d1.should.not.be.withinDate(test.d2, test.d3); | ||
}).should.fail( | ||
'expected Thu May 30 2013 not to be within Wed May 29 2013 and Fri May 31 2013' | ||
); | ||
}.should.fail( | ||
"expected Thu May 30 2013 not to be within Wed May 29 2013 and Fri May 31 2013" | ||
)); | ||
}); | ||
@@ -449,4 +539,4 @@ }); | ||
describe('when given a date that is not between two dates', function() { | ||
beforeEach(function() { | ||
describe("when given a date that is not between two dates", function () { | ||
beforeEach(function () { | ||
this.d1 = new Date(2013, 4, 28); | ||
@@ -457,14 +547,14 @@ this.d2 = new Date(2013, 4, 29); | ||
it('fails', function() { | ||
it("fails", function () { | ||
var test = this; | ||
(function() { | ||
(function () { | ||
test.d1.should.be.withinDate(test.d2, test.d3); | ||
}).should.fail( | ||
'expected Tue May 28 2013 to be within Wed May 29 2013 and Fri May 31 2013' | ||
); | ||
}.should.fail( | ||
"expected Tue May 28 2013 to be within Wed May 29 2013 and Fri May 31 2013" | ||
)); | ||
}); | ||
describe('when negated', function() { | ||
it('passes', function() { | ||
describe("when negated", function () { | ||
it("passes", function () { | ||
this.d1.should.not.be.withinDate(this.d2, this.d3); | ||
@@ -475,4 +565,4 @@ }); | ||
describe('when given three identical dates', function() { | ||
beforeEach(function() { | ||
describe("when given three identical dates", function () { | ||
beforeEach(function () { | ||
this.d1 = new Date(2013, 4, 30); | ||
@@ -483,15 +573,15 @@ this.d2 = new Date(2013, 4, 30); | ||
it('passes', function() { | ||
it("passes", function () { | ||
this.d1.should.be.withinDate(this.d2, this.d3); | ||
}); | ||
describe('when negated', function() { | ||
it('fails', function() { | ||
describe("when negated", function () { | ||
it("fails", function () { | ||
var test = this; | ||
(function() { | ||
(function () { | ||
test.d1.should.not.be.withinDate(test.d2, test.d3); | ||
}).should.fail( | ||
'expected Thu May 30 2013 not to be within Thu May 30 2013 and Thu May 30 2013' | ||
); | ||
}.should.fail( | ||
"expected Thu May 30 2013 not to be within Thu May 30 2013 and Thu May 30 2013" | ||
)); | ||
}); | ||
@@ -502,22 +592,25 @@ }); | ||
describe('beforeTime', function() { | ||
describe('when comparing two different times', function() { | ||
beforeEach(function() { | ||
this.d1 = new Date(2013, 4, 30, 16, 5, 0) | ||
this.d2 = new Date(2013, 4, 30, 16, 5, 1) | ||
describe("beforeTime", function () { | ||
describe("when comparing two different times", function () { | ||
beforeEach(function () { | ||
this.d1 = new Date(2013, 4, 30, 16, 5, 0); | ||
this.d2 = new Date(2013, 4, 30, 16, 5, 1); | ||
}); | ||
it('passes', function() { | ||
it("passes", function () { | ||
this.d1.should.be.beforeTime(this.d2); | ||
}); | ||
describe('when negated', function() { | ||
it('fails', function() { | ||
describe("when negated", function () { | ||
it("fails", function () { | ||
var test = this; | ||
(function() { | ||
(function () { | ||
test.d1.should.not.be.beforeTime(test.d2); | ||
}).should.fail( | ||
'expected ' + chai.datetime.formatTime(this.d1) + ' not to be before ' + chai.datetime.formatTime(this.d2) | ||
); | ||
}.should.fail( | ||
"expected " + | ||
chai.datetime.formatTime(this.d1) + | ||
" not to be before " + | ||
chai.datetime.formatTime(this.d2) | ||
)); | ||
}); | ||
@@ -527,4 +620,4 @@ }); | ||
describe('when comparing identical times', function() { | ||
beforeEach(function() { | ||
describe("when comparing identical times", function () { | ||
beforeEach(function () { | ||
this.d1 = new Date(2013, 4, 30, 16, 5, 0); | ||
@@ -534,14 +627,17 @@ this.d2 = new Date(2013, 4, 30, 16, 5, 0); | ||
it('fails', function() { | ||
it("fails", function () { | ||
var test = this; | ||
(function() { | ||
(function () { | ||
test.d1.should.be.beforeTime(test.d2); | ||
}).should.fail( | ||
'expected ' + chai.datetime.formatTime(this.d1) + ' to be before ' + chai.datetime.formatTime(this.d2) | ||
); | ||
}.should.fail( | ||
"expected " + | ||
chai.datetime.formatTime(this.d1) + | ||
" to be before " + | ||
chai.datetime.formatTime(this.d2) | ||
)); | ||
}); | ||
describe('when negated', function() { | ||
it('passes', function() { | ||
describe("when negated", function () { | ||
it("passes", function () { | ||
this.d1.should.not.be.beforeTime(this.d2); | ||
@@ -553,5 +649,5 @@ }); | ||
describe('afterTime', function() { | ||
describe('when comparing two different times', function() { | ||
beforeEach(function() { | ||
describe("afterTime", function () { | ||
describe("when comparing two different times", function () { | ||
beforeEach(function () { | ||
this.d1 = new Date(2013, 4, 30, 16, 5, 1); | ||
@@ -561,15 +657,18 @@ this.d2 = new Date(2013, 4, 30, 16, 5, 0); | ||
it('passes', function() { | ||
this.d1.should.be.afterTime(this.d2) | ||
it("passes", function () { | ||
this.d1.should.be.afterTime(this.d2); | ||
}); | ||
describe('when negated', function() { | ||
it('fails', function() { | ||
describe("when negated", function () { | ||
it("fails", function () { | ||
var test = this; | ||
(function() { | ||
test.d1.should.not.be.afterTime(test.d2) | ||
}).should.fail( | ||
'expected ' + chai.datetime.formatTime(this.d1) + ' not to be after ' + chai.datetime.formatTime(this.d2) | ||
); | ||
(function () { | ||
test.d1.should.not.be.afterTime(test.d2); | ||
}.should.fail( | ||
"expected " + | ||
chai.datetime.formatTime(this.d1) + | ||
" not to be after " + | ||
chai.datetime.formatTime(this.d2) | ||
)); | ||
}); | ||
@@ -579,4 +678,4 @@ }); | ||
describe('when comparing two identical times', function() { | ||
beforeEach(function() { | ||
describe("when comparing two identical times", function () { | ||
beforeEach(function () { | ||
this.d1 = new Date(2013, 4, 30, 16, 5, 0); | ||
@@ -586,14 +685,17 @@ this.d2 = new Date(2013, 4, 30, 16, 5, 0); | ||
it('fails', function() { | ||
it("fails", function () { | ||
var test = this; | ||
(function() { | ||
test.d1.should.be.afterTime(test.d2) | ||
}).should.fail( | ||
'expected ' + chai.datetime.formatTime(this.d1) + ' to be after ' + chai.datetime.formatTime(this.d2) | ||
); | ||
(function () { | ||
test.d1.should.be.afterTime(test.d2); | ||
}.should.fail( | ||
"expected " + | ||
chai.datetime.formatTime(this.d1) + | ||
" to be after " + | ||
chai.datetime.formatTime(this.d2) | ||
)); | ||
}); | ||
describe('when negated', function() { | ||
it('passes', function() { | ||
describe("when negated", function () { | ||
it("passes", function () { | ||
this.d1.should.not.be.afterTime(this.d2); | ||
@@ -605,5 +707,5 @@ }); | ||
describe('withinTime', function() { | ||
describe('when given a time between two times', function() { | ||
beforeEach(function() { | ||
describe("withinTime", function () { | ||
describe("when given a time between two times", function () { | ||
beforeEach(function () { | ||
this.d1 = new Date(2013, 4, 30, 16, 5, 1); | ||
@@ -614,15 +716,20 @@ this.d2 = new Date(2013, 4, 30, 16, 5, 0); | ||
it('passes', function() { | ||
it("passes", function () { | ||
this.d1.should.be.withinTime(this.d2, this.d3); | ||
}); | ||
describe('when negated', function() { | ||
it('fails', function() { | ||
describe("when negated", function () { | ||
it("fails", function () { | ||
var test = this; | ||
(function() { | ||
(function () { | ||
test.d1.should.not.be.withinTime(test.d2, test.d3); | ||
}).should.fail( | ||
'expected ' + chai.datetime.formatTime(test.d1) + ' not to be within ' + chai.datetime.formatTime(test.d2) + ' and ' + chai.datetime.formatTime(test.d3) | ||
); | ||
}.should.fail( | ||
"expected " + | ||
chai.datetime.formatTime(test.d1) + | ||
" not to be within " + | ||
chai.datetime.formatTime(test.d2) + | ||
" and " + | ||
chai.datetime.formatTime(test.d3) | ||
)); | ||
}); | ||
@@ -632,4 +739,4 @@ }); | ||
describe('when given a time that is not between two times', function() { | ||
beforeEach(function() { | ||
describe("when given a time that is not between two times", function () { | ||
beforeEach(function () { | ||
this.d1 = new Date(2013, 4, 30, 16, 5, 0); | ||
@@ -640,14 +747,19 @@ this.d2 = new Date(2013, 4, 30, 16, 5, 1); | ||
it('fails', function() { | ||
it("fails", function () { | ||
var test = this; | ||
(function() { | ||
(function () { | ||
test.d1.should.be.withinTime(test.d2, test.d3); | ||
}).should.fail( | ||
'expected ' + chai.datetime.formatTime(test.d1) + ' to be within ' + chai.datetime.formatTime(test.d2) + ' and ' + chai.datetime.formatTime(test.d3) | ||
); | ||
}.should.fail( | ||
"expected " + | ||
chai.datetime.formatTime(test.d1) + | ||
" to be within " + | ||
chai.datetime.formatTime(test.d2) + | ||
" and " + | ||
chai.datetime.formatTime(test.d3) | ||
)); | ||
}); | ||
describe('when negated', function() { | ||
it('passes', function() { | ||
describe("when negated", function () { | ||
it("passes", function () { | ||
this.d1.should.not.be.withinTime(this.d2, this.d3); | ||
@@ -658,4 +770,4 @@ }); | ||
describe('when given three identical times', function() { | ||
beforeEach(function() { | ||
describe("when given three identical times", function () { | ||
beforeEach(function () { | ||
this.d1 = new Date(2013, 4, 30, 16, 5, 1); | ||
@@ -666,15 +778,20 @@ this.d2 = new Date(2013, 4, 30, 16, 5, 1); | ||
it('passes', function() { | ||
it("passes", function () { | ||
this.d1.should.be.withinTime(this.d2, this.d3); | ||
}); | ||
describe('when negated', function() { | ||
it('fails', function() { | ||
describe("when negated", function () { | ||
it("fails", function () { | ||
var test = this; | ||
(function() { | ||
(function () { | ||
test.d1.should.not.be.withinTime(test.d2, test.d3); | ||
}).should.fail( | ||
'expected ' + chai.datetime.formatTime(test.d1) + ' not to be within ' + chai.datetime.formatTime(test.d2) + ' and ' + chai.datetime.formatTime(test.d3) | ||
); | ||
}.should.fail( | ||
"expected " + | ||
chai.datetime.formatTime(test.d1) + | ||
" not to be within " + | ||
chai.datetime.formatTime(test.d2) + | ||
" and " + | ||
chai.datetime.formatTime(test.d3) | ||
)); | ||
}); | ||
@@ -685,5 +802,5 @@ }); | ||
describe('formatTime', function() { | ||
describe('printing the date at the start', function() { | ||
it('prints the date at the beginning of the string', function() { | ||
describe("formatTime", function () { | ||
describe("printing the date at the start", function () { | ||
it("prints the date at the beginning of the string", function () { | ||
var date = new Date(2014, 11, 20, 15, 20, 17, 345); | ||
@@ -694,4 +811,4 @@ chai.datetime.formatTime(date).should.match(/^Sat Dec 20 2014.*/); | ||
describe('printing the time', function() { | ||
it('prints milliseconds with one digit', function() { | ||
describe("printing the time", function () { | ||
it("prints milliseconds with one digit", function () { | ||
var date = new Date(2014, 11, 20, 15, 20, 17, 002); | ||
@@ -701,3 +818,3 @@ chai.datetime.formatTime(date).should.match(/.*15:20:17\.002.*/); | ||
it('prints milliseconds with two digits', function() { | ||
it("prints milliseconds with two digits", function () { | ||
var date = new Date(2014, 11, 20, 15, 20, 17, 097); | ||
@@ -707,3 +824,3 @@ chai.datetime.formatTime(date).should.match(/.*15:20:17\.097.*/); | ||
it('prints milliseconds with three digits', function() { | ||
it("prints milliseconds with three digits", function () { | ||
var date = new Date(2014, 11, 20, 15, 20, 17, 345); | ||
@@ -713,3 +830,3 @@ chai.datetime.formatTime(date).should.match(/.*15:20:17\.345.*/); | ||
it('prints seconds with one digit', function() { | ||
it("prints seconds with one digit", function () { | ||
var date = new Date(2014, 11, 20, 15, 20, 7, 345); | ||
@@ -719,3 +836,3 @@ chai.datetime.formatTime(date).should.match(/.*15:20:07.*/); | ||
it('prints seconds with two digits', function() { | ||
it("prints seconds with two digits", function () { | ||
var date = new Date(2014, 11, 20, 15, 20, 49, 345); | ||
@@ -725,3 +842,3 @@ chai.datetime.formatTime(date).should.match(/.*15:20:49.*/); | ||
it('prints minutes with one digit', function() { | ||
it("prints minutes with one digit", function () { | ||
var date = new Date(2014, 11, 20, 15, 6, 49, 345); | ||
@@ -731,3 +848,3 @@ chai.datetime.formatTime(date).should.match(/.*15:06:49.*/); | ||
it('prints minutes with two digits', function() { | ||
it("prints minutes with two digits", function () { | ||
var date = new Date(2014, 11, 20, 15, 31, 49, 345); | ||
@@ -737,3 +854,3 @@ chai.datetime.formatTime(date).should.match(/.*15:31:49.*/); | ||
it('prints hours with one digit', function() { | ||
it("prints hours with one digit", function () { | ||
var date = new Date(2014, 11, 20, 3, 20, 49, 345); | ||
@@ -743,3 +860,3 @@ chai.datetime.formatTime(date).should.match(/.*03:20:49.*/); | ||
it('prints hours with two digits', function() { | ||
it("prints hours with two digits", function () { | ||
var date = new Date(2014, 11, 20, 17, 20, 49, 345); | ||
@@ -750,5 +867,5 @@ chai.datetime.formatTime(date).should.match(/.*17:20:49.*/); | ||
describe('printing the timezone', function() { | ||
it('prints the local timezone', function() { | ||
var date = new Date('2014-12-20T15:20:17.345Z'); | ||
describe("printing the timezone", function () { | ||
it("prints the local timezone", function () { | ||
var date = new Date("2014-12-20T15:20:17.345Z"); | ||
chai.datetime.formatTime(date).should.match(/.* \([+-]\d\d:\d\d\)$/); | ||
@@ -759,87 +876,103 @@ }); | ||
describe('getFormattedTimezone', function() { | ||
describe("getFormattedTimezone", function () { | ||
// Note, timezone is given in minutes, negative means it is ahead of UTC. | ||
it('should use a + to indicate the timezone is ahead of UTC', function () { | ||
chai.datetime.getFormattedTimezone(-525).should.equal('+08:45'); | ||
it("should use a + to indicate the timezone is ahead of UTC", function () { | ||
chai.datetime.getFormattedTimezone(-525).should.equal("+08:45"); | ||
}); | ||
it('should use a - to indicate the timezone is behind of UTC', function () { | ||
chai.datetime.getFormattedTimezone(300).should.equal('-05:00'); | ||
it("should use a - to indicate the timezone is behind of UTC", function () { | ||
chai.datetime.getFormattedTimezone(300).should.equal("-05:00"); | ||
}); | ||
it('should use a + when we are in the UTC timezone', function () { | ||
chai.datetime.getFormattedTimezone(0).should.equal('+00:00'); | ||
}) | ||
it("should use a + when we are in the UTC timezone", function () { | ||
chai.datetime.getFormattedTimezone(0).should.equal("+00:00"); | ||
}); | ||
}); | ||
describe('tdd alias', function() { | ||
beforeEach(function() { | ||
describe("tdd alias", function () { | ||
beforeEach(function () { | ||
this.subject = new Date(2013, 4, 30, 16, 5); | ||
}); | ||
it('.equalDate', function() { | ||
it(".equalDate", function () { | ||
assert.equalDate(this.subject, new Date(2013, 4, 30, 17)); | ||
}); | ||
it('.notEqualDate', function() { | ||
it(".notEqualDate", function () { | ||
assert.notEqualDate(this.subject, new Date(2013, 4, 31, 17)); | ||
}); | ||
it('.beforeDate', function() { | ||
it(".beforeDate", function () { | ||
assert.beforeDate(this.subject, new Date(2013, 4, 31)); | ||
}); | ||
it('.notBeforeDate', function() { | ||
it(".notBeforeDate", function () { | ||
assert.notBeforeDate(this.subject, new Date(2013, 4, 30)); | ||
}); | ||
it('.afterDate', function() { | ||
it(".afterDate", function () { | ||
assert.afterDate(this.subject, new Date(2013, 4, 29)); | ||
}); | ||
it('.notAfterDate', function() { | ||
it(".notAfterDate", function () { | ||
assert.notAfterDate(this.subject, new Date(2013, 4, 30)); | ||
}); | ||
it('.withinDate', function() { | ||
assert.withinDate(this.subject, new Date(2013, 4, 29), new Date(2013, 4, 31)); | ||
it(".withinDate", function () { | ||
assert.withinDate( | ||
this.subject, | ||
new Date(2013, 4, 29), | ||
new Date(2013, 4, 31) | ||
); | ||
}); | ||
it('.notWithinDate', function() { | ||
assert.notWithinDate(this.subject, new Date(2013, 4, 31), new Date(2013, 5, 0)); | ||
it(".notWithinDate", function () { | ||
assert.notWithinDate( | ||
this.subject, | ||
new Date(2013, 4, 31), | ||
new Date(2013, 5, 0) | ||
); | ||
}); | ||
it('.equalTime', function() { | ||
it(".equalTime", function () { | ||
assert.equalTime(this.subject, new Date(2013, 4, 30, 16, 5)); | ||
}); | ||
it('.notEqualTime', function() { | ||
it(".notEqualTime", function () { | ||
assert.notEqualTime(this.subject, new Date(2013, 4, 30, 16, 6)); | ||
}); | ||
it('.beforeTime', function() { | ||
it(".beforeTime", function () { | ||
assert.beforeTime(this.subject, new Date(2013, 4, 30, 16, 6)); | ||
}); | ||
it('.notBeforeTime', function() { | ||
it(".notBeforeTime", function () { | ||
assert.notBeforeTime(this.subject, new Date(2013, 4, 30, 16, 5)); | ||
}); | ||
it('.afterTime', function() { | ||
it(".afterTime", function () { | ||
assert.afterTime(this.subject, new Date(2013, 4, 30, 16, 4)); | ||
}); | ||
it('.notAfterTime', function() { | ||
it(".notAfterTime", function () { | ||
assert.notAfterTime(this.subject, new Date(2013, 4, 30, 16, 6)); | ||
}); | ||
it('.withinTime', function() { | ||
assert.withinTime(this.subject, new Date(2013, 4, 30, 16, 4), new Date(2013, 4, 30, 16, 6)); | ||
it(".withinTime", function () { | ||
assert.withinTime( | ||
this.subject, | ||
new Date(2013, 4, 30, 16, 4), | ||
new Date(2013, 4, 30, 16, 6) | ||
); | ||
}); | ||
it('.notWithinTime', function() { | ||
assert.notWithinTime(this.subject, new Date(2013, 4, 30, 16, 6), new Date(2013, 4, 30, 16, 7)); | ||
it(".notWithinTime", function () { | ||
assert.notWithinTime( | ||
this.subject, | ||
new Date(2013, 4, 30, 16, 6), | ||
new Date(2013, 4, 30, 16, 7) | ||
); | ||
}); | ||
}); | ||
}); | ||
})); | ||
}); |
Sorry, the diff of this file is not supported yet
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
Major refactor
Supply chain riskPackage has recently undergone a major refactor. It may be unstable or indicate significant internal changes. Use caution when updating to versions that include significant changes.
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
42356
1080
80
5
7
1