/** I've run these tests from US(EST) **/
/** Testing from the observers location which is US **/
describe('js date testing', function() {
it('build server from UK', function() {
var ukDate = new Date("Mar 25 2015 01:56:24 UTC+0000");
// If I print ukDate as is- I see Tue Mar 24 2015 20:56:24 GMT-0400 (Eastern Daylight Time)
// But lets mock it since we would like the tests to pass as I assume the user is in US.
spyOn(ukDate, 'toLocaleDateString').and.returnValue("3/24/2015");
var val = ukDate.toLocaleDateString();
expect(val).toEqual("3/24/2015");
expect(ukDate.getUTCDate()).toEqual(25);
});
it('build server from another planet that is 22 hours east of UK', function() {
var aliensWatch = new Date("Mar 25 2015 01:56:24 UTC+2200");
// If I print aliensWatch as is- I see Mon Mar 23 2015 23:56:24 GMT-0400 (Eastern Daylight Time)
// But lets mock it since we would like the tests to pass as I assume the user is in US.
spyOn(aliensWatch, 'toLocaleDateString').and.returnValue("3/23/2015");
var val = aliensWatch.toLocaleDateString();
expect(val).toEqual("3/23/2015");
expect(aliensWatch.getUTCDate()).toEqual(24);
});
});
Please Whitelist JSFiddle in your content blocker.
Help keep JSFiddle free for always by one of two ways:
Whitelist JSFiddle in your content blocker (two clicks)
Go PRO and get access to additional PRO features →
Join the 4+ million users, and keep the JSFiddle dream alive.
Ad-free
All ads in the editor and listing pages are turned completely off.
Use pre-released features
You get to try and use features (like the Palette Color Generator) months before everyone else.
Fiddle collections
Sort and categorize your Fiddles into multiple collections.
Private collections and fiddles
You can make as many Private Fiddles, and Private Collections as you wish!
Console
Debug your Fiddle with a minimal built-in JavaScript console.