Skip to content

Commit

Permalink
fix(TestOperation): add specific tests for all operation types
Browse files Browse the repository at this point in the history
  • Loading branch information
Frozen-byte committed Oct 30, 2024
1 parent 58fd8ac commit 4fb5063
Showing 1 changed file with 72 additions and 1 deletion.
73 changes: 72 additions & 1 deletion packages/apollo-angular/testing/tests/operation.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,13 @@ const testSubscription = gql`
}
}
`;
const testMutation = gql`
mutation addHero($hero: String!) {
addHero(hero: $hero) {
name
}
}
`;

describe('TestOperation', () => {
let mock: ApolloTestingBackend;
Expand Down Expand Up @@ -60,7 +67,7 @@ describe('TestOperation', () => {
});
});

test('should close the operation except for subscription', done => {
test('should leave the operation open for a subscription', done => {
const operation = buildOperationForLink(testSubscription, {});
const emittedResults: FetchResult[] = [];

Expand All @@ -84,6 +91,7 @@ describe('TestOperation', () => {
done();
},
});


const testOperation = mock.expectOne(testSubscription);

Expand All @@ -94,6 +102,69 @@ describe('TestOperation', () => {
testOperation.flushData({
heroes: ['second Hero'],
});

testOperation.complete();
});

test('should close the operation after a query', done => {
const operation = buildOperationForLink(testQuery, {});
const emittedResults: FetchResult[] = [];

execute(link, operation).subscribe({
next(result) {
emittedResults.push(result);
},
complete() {
expect(emittedResults).toEqual([
{
data: {
heroes: ['first Hero'],
},
}
]);
done();
},
});

const testOperation = mock.expectOne(testQuery);

testOperation.flushData({
heroes: ['first Hero'],
});

testOperation.flushData({
heroes: ['second Hero'],
});
});

test('should close the operation after a mutation', done => {
const operation = buildOperationForLink(testMutation, {hero: 'firstHero'});
const emittedResults: FetchResult[] = [];

execute(link, operation).subscribe({
next(result) {
emittedResults.push(result);
},
complete() {
expect(emittedResults).toEqual([
{
data: {
heroes: ['first Hero'],
},
},
]);
done();
},
});

const testOperation = mock.expectOne(testMutation);

testOperation.flushData({
heroes: ['first Hero'],
});

testOperation.flushData({
heroes: ['second Hero'],
});
});
});

0 comments on commit 4fb5063

Please sign in to comment.