Closed nerg4l closed 3 years ago
It seems it has nothing to do with arrays. It is related to fragments. Which makes me think I use the lib incorrectly.
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 Entry {
id
}
`;
apollo.watchQuery({
query: TEST_QUERY,
}).valueChanges.subscribe(result => {
const data = result.data as any;
expect(data.responseEntity.body).toBeTruthy();
expect(data.responseEntity.body).not.toEqual({});
expect(data.responseEntity.body.id).toEqual(1);
done();
});
const op = controller.expectOne('testQuery');
op.flush({
data: { responseEntity: { body: { id: 1, }, }, },
});
});
});
My bad I forgot to add __typename
.
I've spent about 2 hours debugging the same problem until I found this Github issue 😅
@Maximaximum do you think there is a place we could add this to the docs to save people time?
@Urigo I believe this page has to be updated: https://apollo-angular.com/docs/development-and-testing/testing/#expecting-and-answering-operations
Strangely enough, even though it contains a sample flush
usage, it does not even contain the __typename
propery.
@Maximaximum are you up to creating a Pull Request to the docs?
@Urigo I'd love to, but unfortunately I'm too busy this week
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.
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.