Skip to content

global.Date not mocked when window.Date exists #69

@jfstephe

Description

@jfstephe

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

function register(new_timezone, glob) {
if (!glob) {
if (typeof window !== 'undefined') {
glob = window;
} else {
glob = global;
}
}

...assumes one or the other but not both.

As a workaround I'm doing:

timezoneMock.register(timezone);
global.Date = window.Date;

/// ...tests

timezoneMock.unregister();
global.Date = window.Date;

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions