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

FakeDate does not accept a timestamp value #1069

Closed
@EoinF

Description

@EoinF

Expected Behaviour: Passing a timestamp value into the Date object, as shown below, will produce a Date with that timestamp
Actual Behaviour: The timestamp is ignored and the current Date is used

In later versions (0.8.21 and onwards) this is happening, while using fakeAsync(worked with 0.8.20 and earlier)

The following code sample demonstrates this:

it('should set the right date', fakeAsync(() => {
    test();
    tick(1000);
    console.log("second", Date, new Date(0));
  }));

  async function test() {
    await (new Promise(resolve => {
      resolve();
    }));
    console.log("first", Date, new Date(0));
  }

The output is:

'first', function FakeDate() { ... }, Thu Apr 05 2018 11:05:19 GMT+0200 (CEST)
'second', function Date() { ... }, Thu Jan 01 1970 01:00:00 GMT+0100 (CET)

The first line of output is using the FakeDate object which is ignoring the value passed in and just producing the current Date.
The second line is working as expected.

This only occurs inside an async block, after an 'await' has been used

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions