lundi 4 juin 2018

Property 'jasmineMatches' is missing in type 'x'

After ng test

Expected output: i get pass/fail on x amount of tests.

Actual ouput:

ERROR in src/app/todo-data.service.spec.ts(19,45): error TS2345: Argument of type 'Todo[]' is not assignable to parameter of type 'Expected<Observable<Todo[]>>'.
  Type 'Todo[]' is not assignable to type 'ObjectContaining<Observable<Todo[]>>'.
    Property 'jasmineMatches' is missing in type 'Todo[]'.

In my todo class i don't have a jasminematches property, but this might not be the root problem.

todo.ts:

export class Todo {
  id: number;
  title: string = '';
  complete: boolean = false;

  constructor(values: Object = {}) {
    Object.assign(this, values);
  }
}

todo-data.service.spec.ts

import {TestBed, async, inject} from '@angular/core/testing';
import {Todo} from './todo';
import {TodoDataService} from './todo-data.service';

...

  describe('#getAllTodos()', () => {

    it('should return an empty array by default', inject([TodoDataService],
      (service: TodoDataService) => {
      expect(service.getAllTodos()).toEqual(<Todo[]>[]);
    }));

...

todo-data.service.ts

import { Injectable } from '@angular/core';
import { Todo } from './todo';
import { ApiService } from './api.service';
import { Observable } from 'rxjs';

...

export class TodoDataService {

  constructor(private api: ApiService) { }

  getAllTodos(): Observable<Todo[]> {
    return this.api.getAllTodos();
  }

...

Please advise how to start deconstructing this error in order to write a correct test.

Aucun commentaire:

Enregistrer un commentaire