Skip to content
This repository was archived by the owner on Apr 12, 2024. It is now read-only.

Unit tests fail on chrome #3033

Closed
wagnerfrancisco opened this issue Jun 23, 2013 · 5 comments
Closed

Unit tests fail on chrome #3033

wagnerfrancisco opened this issue Jun 23, 2013 · 5 comments

Comments

@wagnerfrancisco
Copy link

Hi, I just downloaded the angular.js, tried to run the unit tests and one test failed. In the angular-mockSpecs.js file there is the "should fake getLocalDateString method" test. The second expectation fails:

var t1 = new angular.mock.TzDate(0, 0);
expect(t1.toLocaleDateString()).toMatch('1970');

The result is:

"Expected '31/12/1969' to match '1970'".

The reason of the error is that chrome implementation of Date.toLocaleDateString considers the timezone (I'm using gmt-2 in Brazil). Instead of printing something like 01/01/1970 it prints 31/12/1969).

I tried to run the tests on Chrome 27.0.1453.116 m. All the tests run perfectly on Firefox.

Thanks.

@btford btford closed this as completed Aug 24, 2013
@btford
Copy link
Contributor

btford commented Aug 24, 2013

As part of our effort to clean out old issues, this issue is being automatically closed since it has been inactivite for over two months.

Please try the newest versions of Angular (1.0.8 and 1.2.0-rc.1), and if the issue persists, comment below so we can discuss it.

Thanks!

@just-boris
Copy link
Contributor

@btford I have this issue on the latest master.
I am from Saint Petersburg and my timezome is GMT+4

I try get some toStrings and I get the following results

var date = new Date(-14400000) 

date.toString() // Thu Jan 01 1970 00:00:00 GMT+0400 (MSK)
d.toLocaleDateString() // 12/31/1969
d.toLocaleString() // 12/31/1969 11:00:00 PM

Now the test ngMock TzDate should fake getLocalDateString method always failing to me, so I ignore this fail when run build locally and I have to check travis build results of my pull requests, because I am not sure, that I hasn't broken this test really

@just-boris
Copy link
Contributor

I suggest to make same changes, that and in a getHous test, landed by 0c65f1a

@ryanphung
Copy link

@btford I think the issue still exists on the latest master as of now. I've just encountered it when forking and testing the latest master.

Chrome 39.0.2171 (Mac OS X 10.9.5) ngMock TzDate should fake getLocalDateString method FAILED
    Expected '12/31/1969' to match '1970'.
    Error: Expected '12/31/1969' to match '1970'.
        at null.<anonymous> (/Users/ryanphung/Projects/AngularJS/angular.js/test/ngMock/angular-mocksSpec.js:35:39)

@ryanphung
Copy link

Upon further investigation, I think it looks like a Webkit issue (both Chrome and Safari has it). In both Chrome and Safari:

> new Date(0).toLocaleString()
< "1 January, 1970 7:30:00 am GMT+7:30"
> new Date(0).getTimezoneOffset()
< -480

My timezone is Singapore (GMT+8 - and we don't have DST here), so I'm not sure where getTimezoneOffset() gets the timezone GMT+7.30 from.

In Firefox:

> new Date(0).toLocaleString()
< "01/01/1970 7:30:00 am"
> new Date(0).getTimezoneOffset()
< -450

Firefox also gets my timezone wrong: GMT+7.30, but at least it's wrong consistently.

Since tzDate make use of getTimezoneOffset() to determine the local timezone (

var localOffset = new Date(timestamp).getTimezoneOffset();
self.offsetDiff = localOffset*60*1000 - offset*1000*60*60;
self.date = new Date(timestamp + self.offsetDiff);
), this explains why the test passed on Firefox but failed on Chrome. I haven't managed to test it in Safari due to other issues.

@wagnerfrancisco @just-boris if this is not the same issue you're facing, please let me know, I'll create a new issue for it. Thanks!

Edit: I'm quite new to this community. The above looks like a bug in Firefox / Chrome / Safari, but I guess even though they are browsers bug, AngularJS is expected to workaround those - so it seems a fix is needed in tzDate rather than the test case. Any idea if this is the right direction to proceed?

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants