Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Test: Use Sinon.js instead of FakeDate #383

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Test: Use Sinon.js instead of FakeDate
Note: lolex's 3664eb8d90dd1d6fa04a098f77b77b19a6bb5850 sha corresponds
to its 1.1.0 npm version (version is present on npm, but not git tagged
accordingly).

Ref #374
Fixes #382
  • Loading branch information
rxaviers committed Jan 12, 2015
commit 068f72b21e6bad0bdd84e56663f44b3f51e3a643
4 changes: 3 additions & 1 deletion bower.json
Original file line number Diff line number Diff line change
Expand Up @@ -14,11 +14,13 @@
},
"devDependencies": {
"es5-shim": "3.4.0",
"lolex": "sinonjs/lolex#3664eb",
"make-plural": "eemeli/make-plural.js#2.1.2",
"messageformat": "SlexAxton/messageformat.js#debeaf4",
"qunit": "1.16.0",
"requirejs": "2.1.9",
"requirejs-plugins": "1.0.2",
"requirejs-text": "2.0.10"
"requirejs-text": "2.0.10",
"sinon": "1.12.2"
}
}
7 changes: 6 additions & 1 deletion test/unit.js
Original file line number Diff line number Diff line change
@@ -1,8 +1,13 @@
require.config({
paths: {
cldr: "../external/cldrjs/dist/cldr",
"cldr-data": "../external/cldr-data",
cldr: "../external/cldrjs/dist/cldr",
json: "../external/requirejs-plugins/src/json",

// Sinon.js dependency.
lolex: "../external/lolex/lolex",

sinon: "../external/sinon/lib/sinon",
src: "../src",
text: "../external/requirejs-text/text"
},
Expand Down
35 changes: 14 additions & 21 deletions test/unit/date/parse.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
define([
"cldr",
"sinon",
"src/date/parse",
"src/date/parse-properties",
"src/date/start-of",
Expand All @@ -13,7 +14,7 @@ define([

"cldr/event",
"cldr/supplemental"
], function( Cldr, parse, parseProperties, startOf, tokenizer, numberTokenizerProperties,
], function( Cldr, sinon, parse, parseProperties, startOf, tokenizer, numberTokenizerProperties,
enCaGregorian, enNumbers, likelySubtags, timeData, weekData ) {

var cldr, date1, date2, FakeDate, midnight;
Expand Down Expand Up @@ -195,31 +196,26 @@ QUnit.test( "should parse month (MMMMM|LLLLL)", function( assert ) {
*/

QUnit.test( "should parse day (d) with no padding", function( assert ) {
var OrigDate;
var clock;

date1 = new Date();
date1.setDate( 2 );
date1 = startOf( date1, "day" );
assertParse( assert, "2", "d", cldr, date1 );

/* globals Date:true */
// Test #323 - Day parsing must use the correct day range given its corresponding month/year.
OrigDate = Date;
Date = FakeDate;

// `sinon.useFakeTimers( date )` overwrites Date with a custom implementation, where now = date.
date1 = new Date( 2014, 1, 28 );
date1 = startOf( date1, "day" );
FakeDate.today = new Date( 2014, 1 );
clock = sinon.useFakeTimers( new Date( 2014, 1 ).getTime() );
assertParse( assert, "29", "d", cldr, null );
assertParse( assert, "28", "d", cldr, date1 );
clock.restore();

date2 = new Date( 2016, 1, 29 );
date2 = startOf( date2, "day" );
FakeDate.today = new Date( 2016, 1 );
clock = sinon.useFakeTimers( new Date( 2016, 1 ).getTime() );
assertParse( assert, "30", "d", cldr, null );
assertParse( assert, "29", "d", cldr, date2 );

Date = OrigDate;
clock.restore();
});

QUnit.test( "should parse day (dd) with padding", function( assert ) {
Expand All @@ -230,28 +226,25 @@ QUnit.test( "should parse day (dd) with padding", function( assert ) {
});

QUnit.test( "should parse day of year (D) with no padding", function( assert ) {
var OrigDate;
var clock;

date1 = new Date();
date1.setMonth( 0 );
date1.setDate( 2 );
date1 = startOf( date1, "day" );
assertParse( assert, "2", "D", cldr, date1 );

/* globals Date:true */
// Test #323 - Day of year parsing must use the correct day range given leap year into account.
OrigDate = Date;
Date = FakeDate;

FakeDate.today = new Date( 2014, 1 );
// `sinon.useFakeTimers( date )` overwrites Date with a custom implementation, where now = date.
clock = sinon.useFakeTimers( new Date( 2014, 1 ).getTime() );
assertParse( assert, "366", "D", cldr, null );
clock.restore();

// date1 = last day of 2016
date1 = new Date( 2017, 0, 0 );
FakeDate.today = new Date( 2016, 1 );
clock = sinon.useFakeTimers( new Date( 2016, 1 ).getTime() );
assertParse( assert, "366", "D", cldr, date1 );

Date = OrigDate;
clock.restore();
});

QUnit.test( "should parse day of year (DD|DDD) with padding", function( assert ) {
Expand Down