Skip to content

Regression: fakeAsync breaks Date in 6.0.0-rc.2 #23223

@jnizet

Description

@jnizet

I'm submitting a...


[x] Regression (a behavior that used to work and stopped working in a new release)
[ ] Bug report  
[ ] Feature request
[ ] Documentation issue or request
[ ] Support request => Please do not submit support request here, instead see https://github.com/angular/angular/blob/master/CONTRIBUTING.md#question

Current behavior

Execute the following test suite:

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.

Expected behavior

The test should pass

Environment


Angular version: 6.0.0-rc.2
Zone.js version 0.8.25
 
- Node version: 8.11.1  
- Platform: Mac 

Metadata

Metadata

Assignees

No one assigned

    Labels

    area: testingIssues related to Angular testing features, such as TestBedregressionIndicates than the issue relates to something that worked in a previous version

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions