Тип аргумента не присваивается типа - PullRequest
0 голосов
/ 04 июля 2018

Я хочу проверить функцию, и у меня возникла проблема с проверкой типа.

Я получаю следующую ошибку:

Аргумент типа «TestDates []» не может быть назначен для параметра типа сегодня «TestDates'.Property„“отсутствует в типе„TestDates []“.

Как я могу это решить?

 it('should create the table', () => {
    const testDataMock = new DataItems([new TestDates(new Date(), new Date(), new Date())],
      [new DataTable('123456', date, 1.05728,
        undefined, -0.123, -0.123)]
    );
    const spy = spyOn(component, 'createTable');
    component.createMatrixTable(testDataMock);

    fixture.detectChanges();
    expect(spy).toHaveBeenCalled();
  });

TestDates

export class TestDates {
  constructor(public today: Date,
              public lastMonth: Date,
              public lastDay: Date) {
  }
}

createMatrixTable

createMatrixTable(items: DataItems) {
    const {lastDay, lastMonth, today} = items.dateValues[0];
    const spreadOrQuote = this.data.type === 1 ? 'in' : 'out';
            this.createTable(items, columns);
          }

После пробного запуска я получаю следующее сообщение:

TypeError: Невозможно прочитать свойство 'lastDay' из неопределенного

1 Ответ

0 голосов
/ 04 июля 2018

Первый параметр в new DataItems(.... - это массив TestDates, я думаю, он ожидает только TestDates объект, поэтому вы получаете Argument of type 'TestDates[]' is not..... Попробуйте это:

it('should create the table', () => {
    const testDataMock = new DataItems(new TestDates(new Date(), new Date(), new Date()),
      [new DataTable('123456', date, 1.05728,
        undefined, -0.123, -0.123)]
    );
    const spy = spyOn(component, 'createTable');
    component.createMatrixTable(testDataMock);

    fixture.detectChanges();
    expect(spy).toHaveBeenCalled();
  });
Добро пожаловать на сайт PullRequest, где вы можете задавать вопросы и получать ответы от других членов сообщества.
...