question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

unit-testing a service which uses apollo-angular

See original GitHub issue

Hey,

i want to test a service which uses apollo. The Service looks like that:

import { Injectable } from '@angular/core';
import { Apollo } from 'apollo-angular';
import gql from 'graphql-tag';

const MuUserRegister = gql`
  mutation {userRegister (
      email:"4",
      username: "4"
      password: "test"
      ) {
    data {
      _id,
      email,
      username
    }
  }}
`

@Injectable()
export class AuthService {
  constructor(private apollo: Apollo) {}

  register() {
    return this.apollo.mutate({
      mutation: MuUserRegister
    });
  }
}

The test looks like that:

import { AuthService } from './auth.service'

describe('test service', () => {
  it('test Auth Service', (done: DoneFn) => {
    let service = new AuthService(???)
    let test = service.register()
    test.subscribe(({data}) => {
      expect(data).toEqual(null);
      done()
    });
  });
});

My question is: what and how should i provide the apollo module/client in the line let service = new AuthService(???) Is this the right approach to unit-test the apollo-client?

thx in advance

Issue Analytics

  • State:closed
  • Created 6 years ago
  • Comments:10 (3 by maintainers)

github_iconTop GitHub Comments

github_iconTop Results From Across the Web

Testing – Angular - GraphQL Code Generator
The apollo-angular/testing module exports a ApolloTestingModule module and ApolloTestingController service which simplifies the testing of ...
Read more >
unit-testing a service which uses apollo-angular #348 - GitHub
Hey, i want to test a service which uses apollo. The Service looks like that: import { Injectable } from '@angular/core'; import {...
Read more >
Testing Apollo GraphQL in your Angular application - Medium
Testing Apollo so far was very tricky, for us who are used to simplicity and ... So here is how to setup testing...
Read more >
Integration testing - Apollo GraphQL Docs
Apollo Server uses a multi-step request pipeline to validate and execute incoming GraphQL operations. This pipeline supports integration with custom plugins ...
Read more >
Apollo Client - GraphQL Testing In Angular Component
Apollo Client – GraphQL Testing In Angular Component · 1) Install Jest · 2) Setup Jest In Angular · 3) Set GraphQL Query...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found