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.

Apollo tests fail with --codeCoverage but pass without

See original GitHub issue

Intended outcome: Running ng test --codeCoverage=true --no-watch should pass, since running without --codeCoverage passes

Actual outcome: The test fails with TypeError: Cannot read property 'use' of undefined this looks to be in (http://localhost:9877/_karma_webpack_/node_modules/apollo-angular/fesm2015/ngApollo.js:239:1). It seems Apollo is not being injected correctly.

How to reproduce the issue: When testing a Query from apollo-angular in a service (not a component) the tests will pass when run normally but will fail when generating code coverage. See the repository at https://github.com/aaraggornn/apollo-error-test for a reproduction.

Run npm run test to pass and npm run test:cc to fail (using --codeCoverage)

Versions “apollo-angular”: “^1.7.0”, “apollo-client”: “^2.6.4”, “typescript”: “~3.5.3”, “@angular/core”: “~8.2.8”, “graphql”: “^14.5.8”, “graphql-tag”: “^2.10.1”,

Issue Analytics

  • State:closed
  • Created 4 years ago
  • Reactions:6
  • Comments:7

github_iconTop GitHub Comments

4reactions
nicky-lenaerscommented, Dec 5, 2019

@aaraggornn I have found a temporary workaround. You’ll need to inject Apollo manually in the extended Mutation class and call super() with the provided apollo instance:

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

@Injectable({ providedIn: 'root' })
export class SomeMutationGQL extends Mutation {

  constructor(apollo: Apollo) {
    super(apollo); // <-- use this to prevent  the error from throwing
  }

  public document = gql`
    mutation ...
  `;
}

It will work with --codeCoverage turned on.

1reaction
aaraggornncommented, Oct 28, 2019

This also happens with apollo-angular 1.8.0

Read more comments on GitHub >

github_iconTop Results From Across the Web

Apollo tests fail with --codeCoverage but pass without #1341
It seems Apollo is not being injected correctly. How to reproduce the issue: When testing a Query from apollo-angular in a service (not...
Read more >
Jest codeCoverage not working as expected - Help
I'm testing using a very simliar method to what is mentioned in the docs, but still the code coverage tool is giving these...
Read more >
Jest passing tests but --covering option not picking up files
I have written two tests for a typescript class. Those two tests pass so jest successfully retrieves the test files. I then use...
Read more >
Increasing Unit Test Coverage with jest-it-up
After configuring a threshold value, Jest will fail the build if a developer adds new code to the project without adequate unit tests....
Read more >
Testing custom Apollo hooks with React Testing Library
The second test case it's pretty similar, but now we test when there's an error. it("should return error when request fails", async ...
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