vendredi 17 février 2017

How to test Date(Invalid Date) with jasmine

To simplify, lets see this function getting date and returning a date modified (start of day):

const getStartOfDay = date => {
    const newDate = new Date(date);
  newDate.setHours(0, 0, 0, 0);
  return newDate;
}

Now I want to implement some tests with invalid values i.e: getStartOfDay(new Date("HELLO")); function returns Date(Invalid Date).

I tried to test like:

expect(util.getStartOfDay("hello")).toBe(new Date("hello"));

But I get:

Expected Date(Invalid Date) to equal Date(Invalid Date).

Same error with toEquals()...

Other dates I compare with getTime() but here I cant... So I get stucked...

Any idea of how can I test it?

Aucun commentaire:

Enregistrer un commentaire