Skip to content

Commit

Permalink
polish: fix test
Browse files Browse the repository at this point in the history
I introduced use of expect.fail() in #3760 mistakenly believing that expect.fail() will always cause the test to fail.

Actually, expect.fail() just throws an error, and that error is wrapped is wrapped by GraphQL and then filtered, so the lines are reached.

Fortunately, it's not a problem that the line is reached, as long as it is filtered correctly. The number of calls to next() may be more than 1 (in our case it is 2) depending on the # of ticks that it takes for the deferred fragment to resolve.

So the test as written is intending to be overly strict, but is broken and so functions as desires. This commit makes no change to the test semantics, but changes the comment, the coverage ignore statement, and removes the confusing use of expect.fail, so that the test semantics are more clearly apparent.
  • Loading branch information
yaacovCR committed Jan 5, 2023
1 parent 7a609a2 commit a6f75e6
Showing 1 changed file with 4 additions and 4 deletions.
8 changes: 4 additions & 4 deletions src/execution/__tests__/stream-test.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { assert, expect } from 'chai';
import { assert } from 'chai';
import { describe, it } from 'mocha';

import { expectJSON } from '../../__testUtils__/expectJSON.js';
Expand Down Expand Up @@ -1422,9 +1422,8 @@ describe('Execute: stream directive', () => {
[Symbol.asyncIterator]: () => ({
next: () => {
if (requested) {
/* c8 ignore next 3 */
// Not reached, iterator should end immediately.
expect.fail('Not reached');
// Ignores further errors when filtered.
return Promise.reject(new Error('Oops'));
}
requested = true;
const friend = friends[0];
Expand All @@ -1438,6 +1437,7 @@ describe('Execute: stream directive', () => {
},
return: () => {
returned = true;
// Ignores errors from return.
return Promise.reject(new Error('Oops'));
},
}),
Expand Down

0 comments on commit a6f75e6

Please sign in to comment.