unit-testing a service which uses apollo-angular
See original GitHub issueHey,
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:
- Created 6 years ago
- Comments:10 (3 by maintainers)
Top 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 >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
https://www.apollographql.com/docs/angular/guides/testing.html#An-introduction
That is the current way to test apollo-angular: https://www.apollographql.com/docs/graphql-tools/mocking.html