Skip to content

Date object is converted to String by cy.task #32861

@KrzGruszcz

Description

@KrzGruszcz

Current behavior

Date object is converted to a String when it's an argument in cy.task.

Cypress config file (task definition):

date(date) {
  const date_2 = new Date();

  console.log(date);
  console.log(date_2);
  console.log(Object.prototype.toString.call(date));
  console.log(Object.prototype.toString.call(date_2));
},

spec file:

  it.('should pass a Date arg in cy.task', function () {
    const date = new Date()
    cy.log(Object.prototype.toString.call(date))
    cy.task('date', date)
  });

The cypress cy.log command is printing:

Image

The terminal log is printing:

Image

The type of the date argument was changed as we can see.

Desired behavior

Type of the argument should not be changed.

Test code to reproduce

Refer to current behavior section.

Cypress Version

15.4.0

Debug Logs

Other

No response

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