How do I mock hybrid type interfaces with Jasmine?

  angular, d3.js, jasmine, typescript

I am trying to mock ScaleTime<...> hybrid type interface from d3.js. It goes like this:

export interface ScaleTime<Range, Output, Unknown = never> {
  (value: Date | NumberValue): Output | Unknown;
  invert(value: NumberValue): Date;
  // ...
}

I can create a spy object for the methods:

const scaleTimeSpy = jasmine.createSpyObj('ScaleTime', ['invert' /*...*/]);
scaleTimeSpy.ticks.and.returnValue([date1, date2]);

And I can create a spy for interface call signature (value: Date | NumberValue): Output | Unknown;):

const scaleTimeFuncionSpy = jasmine.createSpy('ScaleTime');
scaleTimeFuncionSpy.and.returnValue(1);

But how do I combine both in one object? How do I refer an interface call signature?

Source: Angular Questions

Leave a Reply

This site uses Akismet to reduce spam. Learn how your comment data is processed.