0

I want to unit test a typescript function that uses apollo/graphql. I have tried several examples that I have found around here, but none of them work for me. Given my zero experience testing, from the following simple example, could you give me a solution?

LIST = gql`
  {
    music_list {
      id title artirst
    }
  }
`;

class Music {
  id: string,
  title: string,
  artist: string
}


class MusicService {

  constructor(provider: Apollo) {
    super(provider, 'music');
  }

  music_list(): Observable<Array<Music>> {
    return this.apollo.query({
      query: LIST,
    })
    .pipe(map((res: any) => res?.data?.music_list.map((r: any) => new Music(r))))
    .pipe(catchError((error: any) => this.Errors(error)));
  }
}

From this code example I want to perform a test for function music_list() of class MusicService. I hope someone can help me.

Thank you very much. Greetings.

Esther_5
  • 151
  • 2
  • 10

0 Answers0