-
Notifications
You must be signed in to change notification settings - Fork 35
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
global.Date not mocked when window.Date exists #69
Comments
In your setup, do both If not both, probably an easy fix to check function registerInternal(glob) {
if (glob.Date !== MockDate) {
_Date = glob.Date;
exports._Date = glob.Date;
}
glob.Date = MockDate;
}
function register(new_timezone, glob) {
timezone = new_timezone || 'US/Pacific';
if (glob) {
registerInternal(glob);
} else {
if (typeof window !== 'undefined') {
registerInternal(window);
}
if (typeof global !== 'undefined') {
registerInternal(global);
}
}
if (!orig_object_toString) {
orig_object_toString = Object.prototype.toString;
Object.prototype.toString = mockDateObjectToString;
}
} |
Hi, thanks for the quick response! Yes we have both Global (from node) and Window (from the UI test lib). Strangely I've re-run this without my workaround and it's working, but this definitely was an issue and I think it makes sense that an issue is there. It could be a race condition somewhere in my code, not sure. I did manage to run the code you suggested above and that continued to work. The unregister would need some tweaking too I think. I'm not in a position to easily do a PR I'm afraid due to company restrictions. This isn't hurting me ATM and there's a workaround so maybe for vNext? At least it's recorded for others :-) |
I was wondering if the fake Anyway, will leave this here, if someone else runs into a similar issue in the future they can try the fix and hopefully send a PR if it works =). |
Hi,
First off, thanks for this. It helped us be able to test some code with date_fns that would have been a nightmare otherwise.
The problem:
If you have UI tests running in node then you have a window object and a global. The code at:
timezone-mock/index.js
Lines 265 to 272 in 780f8c2
...assumes one or the other but not both.
As a workaround I'm doing:
The text was updated successfully, but these errors were encountered: