Skip to content

Commit

Permalink
Use parent instead of global to allow tests to run in a browser.
Browse files Browse the repository at this point in the history
  • Loading branch information
timrwood committed Feb 23, 2016
1 parent fa115d7 commit 1b05d56
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 7 deletions.
7 changes: 4 additions & 3 deletions tests/helpers/helpers.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,8 @@
var moment = require('../../index');
var getTimezoneOffset = Date.prototype.getTimezoneOffset;
var toTimeString = Date.prototype.toTimeString;
var oldIntl = global.Intl;
var parent = (typeof window !== 'undefined' && window) || (typeof global !== 'undefined' && global);
var oldIntl = parent.Intl;

function getUTCOffset (m) {
if (m.utcOffset !== undefined) {
Expand Down Expand Up @@ -48,7 +49,7 @@ function mockToTimeString(name, format) {
}

function testGuess(test, name, mostPopulatedFor) {
global.Intl = undefined;
parent.Intl = undefined;

if (mostPopulatedFor.offset) {
mockTimezoneOffset(name);
Expand All @@ -64,7 +65,7 @@ function testGuess(test, name, mostPopulatedFor) {

Date.prototype.getTimezoneOffset = getTimezoneOffset;
Date.prototype.toTimeString = toTimeString;
global.Intl = oldIntl;
parent.Intl = oldIntl;
test.done();
}

Expand Down
9 changes: 5 additions & 4 deletions tests/moment-timezone/guess.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,8 @@ var tz = require("../../").tz;

var getTimezoneOffset = Date.prototype.getTimezoneOffset;
var toTimeString = Date.prototype.toTimeString;
var oldIntl = global.Intl;
var parent = (typeof window !== 'undefined' && window) || (typeof global !== 'undefined' && global);
var oldIntl = parent.Intl;

function mockTimezoneOffset (zone, format) {
Date.prototype.getTimezoneOffset = function () {
Expand All @@ -16,7 +17,7 @@ function mockTimezoneOffset (zone, format) {
}

function mockIntlTimeZone (name) {
global.Intl = {
parent.Intl = {
DateTimeFormat: function () {
return {
resolvedOptions: function () {
Expand All @@ -31,14 +32,14 @@ function mockIntlTimeZone (name) {

exports.guess = {
setUp : function (done) {
global.Intl = undefined;
parent.Intl = undefined;
done();
},

tearDown : function (done) {
Date.prototype.getTimezoneOffset = getTimezoneOffset;
Date.prototype.toTimeString = toTimeString;
global.Intl = oldIntl;
parent.Intl = oldIntl;
done();
},

Expand Down

0 comments on commit 1b05d56

Please sign in to comment.