Description
Do you want to request a feature or report a bug?
Bug
What is the current behavior?
Unit Test suite fails on Chrome at test # 5146
What is the expected behavior?
All test should pass on a clean build.
I've just cloned the '/angular/angular.js' (Version 1.5.1), build it without errors and with the clean build when run the preloaded unit tests with grunt (grunt test:unit) it throws the same error mentioned by @wagnerfrancisco when tests Chrome.
(All the test PASS except this one)
$ grunt test:unit
Running "shell:npm-install" (shell) task
:-) npm dependencies are looking good!
Running "tests:jqlite" (tests) task
17 03 2016 23:06:54.565:WARN [watcher]: All files matched by "/home/cgarcia/Documents/angular.js/src/angular.bind.js" were excluded.
17 03 2016 23:06:54.651:INFO [karma]: Karma v0.13.19 server started at http://localhost:9876/
17 03 2016 23:06:54.660:INFO [launcher]: Starting browser Chrome
17 03 2016 23:06:55.564:INFO [Chrome 49.0.2623 (Linux 0.0.0)]: Connected on socket /#3JfmMhoSkySvkvFcAAAA with id 98102530
Chrome 49.0.2623 (Linux 0.0.0) ngMock TzDate should fake getLocalDateString method FAILED
Expected '12/31/1969' to match '1970'.
Error: Expected '12/31/1969' to match '1970'.
at .<anonymous> (/home/cgarcia/Documents/angular.js/test/ngMock/angular-mocksSpec.js:35:39)
Chrome 49.0.2623 (Linux 0.0.0): Executed 5146 of 5146 (1 FAILED) (21.706 secs / 21.783 secs)
Warning: Karma test(s) failed. Exit code: 1 Use --force to continue.
Aborted due to warnings.
Reproducable: Always
Browser: Chrome 49.0.2623
Operating System: Ubuntu 15.10 (Wily Werewolf)
steps to reproduce:
1)Clone the repository of Angular.js
git clone https://github.com/angular/angular.js.git
2)Building & Testing
Have node v 0.12.4 pre-installed
Have java version 1.8.0_74 pre-installed
Install Grunt & Bower:
npm install -g grunt-cli
npm install -g bower
# Add the main AngularJS repository as an upstream remote to your repository:
git remote add upstream "https://github.com/angular/angular.js.git"
# Install node.js dependencies:
npm install
# Install bower components:
bower install
# Build AngularJS:
grunt package
3)Running the Test Suite
grunt test:unit
The piece of code that runs this test is:
(/angular.js/test/ngMock/angular-mocksSpec.js)
it('should fake getLocalDateString method', function() {
//0 in -3h
var t0 = new angular.mock.TzDate(-3, 0);
expect(t0.toLocaleDateString()).toMatch('1970');
//0 in +0h
var t1 = new angular.mock.TzDate(0, 0);
expect(t1.toLocaleDateString()).toMatch('1970');
//0 in +3h
var t2 = new angular.mock.TzDate(3, 0);
expect(t2.toLocaleDateString()).toMatch('1969');
});
and the code that is referenced:
(/angular.js/src/ngMock/angular-mock.js)
/**
* @ngdoc type
* @name angular.mock.TzDate
* @description
*
* *NOTE*: this is not an injectable instance, just a globally available mock class of `Date`.
*
* Mock of the Date type which has its timezone specified via constructor arg.
*
* The main purpose is to create Date-like instances with timezone fixed to the specified timezone
* offset, so that we can test code that depends on local timezone settings without dependency on
* the time zone settings of the machine where the code is running.
*
* @param {number} offset Offset of the *desired* timezone in hours (fractions will be honored)
* @param {(number|string)} timestamp Timestamp representing the desired time in *UTC*
*
* @example
* !!!! WARNING !!!!!
* This is not a complete Date object so only methods that were implemented can be called safely.
* To make matters worse, TzDate instances inherit stuff from Date via a prototype.
*
* We do our best to intercept calls to "unimplemented" methods, but since the list of methods is
* incomplete we might be missing some non-standard methods. This can result in errors like:
* "Date.prototype.foo called on incompatible Object".
*
* ```js
* var newYearInBratislava = new TzDate(-1, '2009-12-31T23:00:00Z');
* newYearInBratislava.getTimezoneOffset() => -60;
* newYearInBratislava.getFullYear() => 2010;
* newYearInBratislava.getMonth() => 0;
* newYearInBratislava.getDate() => 1;
* newYearInBratislava.getHours() => 0;
* newYearInBratislava.getMinutes() => 0;
* newYearInBratislava.getSeconds() => 0;
* ```
*
*/
angular.mock.TzDate = function(offset, timestamp) {
var self = new Date(0);
if (angular.isString(timestamp)) {
var tsStr = timestamp;
self.origDate = jsonStringToDate(timestamp);
timestamp = self.origDate.getTime();
if (isNaN(timestamp)) {
throw {
name: "Illegal Argument",
message: "Arg '" + tsStr + "' passed into TzDate constructor is not a valid date string"
};
}
} else {
self.origDate = new Date(timestamp);
}
var localOffset = new Date(timestamp).getTimezoneOffset();
self.offsetDiff = localOffset * 60 * 1000 - offset * 1000 * 60 * 60;
self.date = new Date(timestamp + self.offsetDiff);
self.getTime = function() {
return self.date.getTime() - self.offsetDiff;
};
self.toLocaleDateString = function() {
return self.date.toLocaleDateString();
};
self.getFullYear = function() {
return self.date.getFullYear();
};
self.getMonth = function() {
return self.date.getMonth();
};
self.getDate = function() {
return self.date.getDate();
};
self.getHours = function() {
return self.date.getHours();
};
self.getMinutes = function() {
return self.date.getMinutes();
};
self.getSeconds = function() {
return self.date.getSeconds();
};
self.getMilliseconds = function() {
return self.date.getMilliseconds();
};
self.getTimezoneOffset = function() {
return offset * 60;
};
self.getUTCFullYear = function() {
return self.origDate.getUTCFullYear();
};
self.getUTCMonth = function() {
return self.origDate.getUTCMonth();
};
self.getUTCDate = function() {
return self.origDate.getUTCDate();
};
self.getUTCHours = function() {
return self.origDate.getUTCHours();
};
self.getUTCMinutes = function() {
return self.origDate.getUTCMinutes();
};
self.getUTCSeconds = function() {
return self.origDate.getUTCSeconds();
};
self.getUTCMilliseconds = function() {
return self.origDate.getUTCMilliseconds();
};
self.getDay = function() {
return self.date.getDay();
};
// provide this method only on browsers that already have it
if (self.toISOString) {
self.toISOString = function() {
return padNumberInMock(self.origDate.getUTCFullYear(), 4) + '-' +
padNumberInMock(self.origDate.getUTCMonth() + 1, 2) + '-' +
padNumberInMock(self.origDate.getUTCDate(), 2) + 'T' +
padNumberInMock(self.origDate.getUTCHours(), 2) + ':' +
padNumberInMock(self.origDate.getUTCMinutes(), 2) + ':' +
padNumberInMock(self.origDate.getUTCSeconds(), 2) + '.' +
padNumberInMock(self.origDate.getUTCMilliseconds(), 3) + 'Z';
};
}
//hide all methods not implemented in this mock that the Date prototype exposes
var unimplementedMethods = ['getUTCDay',
'getYear', 'setDate', 'setFullYear', 'setHours', 'setMilliseconds',
'setMinutes', 'setMonth', 'setSeconds', 'setTime', 'setUTCDate', 'setUTCFullYear',
'setUTCHours', 'setUTCMilliseconds', 'setUTCMinutes', 'setUTCMonth', 'setUTCSeconds',
'setYear', 'toDateString', 'toGMTString', 'toJSON', 'toLocaleFormat', 'toLocaleString',
'toLocaleTimeString', 'toSource', 'toString', 'toTimeString', 'toUTCString', 'valueOf'];
angular.forEach(unimplementedMethods, function(methodName) {
self[methodName] = function() {
throw new Error("Method '" + methodName + "' is not implemented in the TzDate mock");
};
});
return self;
};
//make "tzDateInstance instanceof Date" return true
angular.mock.TzDate.prototype = Date.prototype;
/* jshint +W101 */
I want to contribute to the angular.js project but I'm not sure if this is a legit problem to work on
sorry if the post is too long :).