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.

Object become empty in flushed object inside test

See original GitHub issue

Describe the bug

When running tests not empty objects replaced with empty objects. From what I tested it seems the use of an array causes this.

To Reproduce Steps to reproduce the behavior:

Run the test below.

import { TestBed } from '@angular/core/testing';
import {
  ApolloTestingModule,
  ApolloTestingController,
} from 'apollo-angular/testing';
import { Apollo, gql } from 'apollo-angular';

describe('UndefinedSpec', () => {
  let controller: ApolloTestingController;

  beforeEach(() => {
    TestBed.configureTestingModule({
      imports: [ApolloTestingModule]
    });
    controller = TestBed.inject(ApolloTestingController);
  });

  afterEach(() => {

    // After every test, assert that there are no more pending requests.
    controller.verify();
  });

  it('undefined', (done) => {
    const apollo = TestBed.inject(Apollo);

    const TEST_QUERY = gql`
  query testQuery {
    responseEntity {
      body { ...TestObjFragment }
    }
  }
  fragment TestObjFragment on TestObj {
    id
  }
`;

    apollo.watchQuery({
      query: TEST_QUERY,
    }).valueChanges.subscribe(result => {
      const data = result.data as any;
      expect(data.responseEntity.body[0]).toBeTruthy();
      expect(data.responseEntity.body[0]).not.toEqual({});
      expect(data.responseEntity.body[0].id).toEqual(1);
      done();
    });

    const op = controller.expectOne('testQuery');

    op.flush({
      data: { responseEntity: { body: [ { id: 1, } ], }, },
    });
  });
});

Expected behavior

Test should pass.

Environment:

  • @apollo/client: 3.3.7
  • apollo-angular: 2.2.0
  • graphql: 15.5.0
  • @angular/core: 10.1.6
  • @angular/cli: 10.1.7
  • typescript: 4.0.5

Additional context

The same definition works just fine in the browser.

Issue Analytics

  • State:closed
  • Created 3 years ago
  • Comments:7

github_iconTop GitHub Comments

1reaction
nerg4lcommented, Jan 29, 2021

My bad I forgot to add __typename.

0reactions
Maximaximumcommented, Nov 15, 2021

@Urigo I’d love to, but unfortunately I’m too busy this week

Read more comments on GitHub >

github_iconTop Results From Across the Web

How do I test for an empty JavaScript object? - Stack Overflow
function isEmpty(obj) { for(var prop in obj) { if(Object.prototype. ... Tested under Node, Chrome, Firefox and IE 9, it becomes evident that for...
Read more >
How to Check if an Object is Empty in JavaScript – JS Java ...
If it returns zero (0), the object is empty. You can now use this method to check if an object is empty with...
Read more >
Testing With Mock Objects - ScalaTest
Testing with mock objects. You can use any Java mocking framework with ScalaTest, or ScalaMock, a Scala mocking alternative. ScalaTest provides just enough ......
Read more >
Emptying a bucket - Amazon Simple Storage Service
When you empty a bucket, you delete all the objects, but you keep the bucket. After you empty a bucket, it cannot be...
Read more >
Testing tools - Django documentation
Makes a GET request on the provided path and returns a Response object, ... is that some database behaviors cannot be tested within...
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