Home > Software design >  How to say "any [type of data]" in angular Jasmine unit test
How to say "any [type of data]" in angular Jasmine unit test

Time:09-23

I'd like to write a test that looks something like this:

expect(myService.myMethod()).toEqual({
      theDate: any Date,
      title: 'My Title',
...
    });

Is there a way in Jasmine to expect against type? So: any string, any number, any Date, etc? Is that legal, or a bad idea?

CodePudding user response:

You can use jasmine.any(Class) to match against any type.

i.e.,

expect(new Date())
  .toEqual(jasmine.any(Date));

See https://jasmine.github.io/api/4.4/jasmine.html for more info.

  • Related