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.

fakeAsync breaks Date constructor #1071

@jnizet

Description

@jnizet

I have reported this bug in Angular (angular/angular#23223), but was asked to report it here. So here it goes:

Environment:
Zone.js v0.8.25, Angule 6.0.0-rc.2.

import { fakeAsync, TestBed } from '@angular/core/testing';

describe('Dates', () => {
  beforeEach(() => {
    TestBed.configureTestingModule({});
  });

  it('should deal with dates correctly in fakeAsync', fakeAsync(() => {
    const jsDate = new Date(1985, 2, 3, 12);
    jsDate.setFullYear(1985);

    expect(isNaN(jsDate.getTime())).toBeFalsy();
    expect(jsDate.getFullYear()).toBe(1985);
    expect(jsDate.getMonth()).toBe(2);
    expect(jsDate.getDate()).toBe(3);
  }));

  it('should deal with dates correctly out of fakeAsync', () => {
    const jsDate = new Date(1985, 2, 3, 12);
    jsDate.setFullYear(1985);

    expect(isNaN(jsDate.getTime())).toBeFalsy();
    expect(jsDate.getFullYear()).toBe(1985);
    expect(jsDate.getMonth()).toBe(2);
    expect(jsDate.getDate()).toBe(3);
  });
});

The second test passes, but the first one fails:

        Expected 3 to be 2.
	Expected 6 to be 3.

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