Skip to content

Commit 505d096

Browse files
authored
polish: clarify filtering test semantics (#3816)
`expect.fail()` was mistakenly introduced in #3760 under the assumption that expect.fail() will always cause the test to fail, and that `.next()` should be called at most once. Actually, thought, `expect.fail()` just throws an error, `.next()` is called more than once, the error is produced and wrapped by GraphQL, but then it is filtered, so the test ultimately passes. Fortunately, that's actually the desired behavior! It's ok if the number of calls to `.next()` is more than 1 (in our case it is 2). The exact number of calls to `.next()` depends on the # of ticks that it takes for the erroring deferred fragment to resolve, which should be as low as possible, but that is a separate objective (with other PRs in the mix already aimed at reducing). So the test as written is intending to be overly strict, but is not actually meeting that goal and so functions as desires. This PR makes no change to the test semantics, but changes the comment, the coverage ignore statement, and removes the potentially confusing use of `expect.fail`, so that the test semantics are more clearly apparent.
1 parent 7a609a2 commit 505d096

File tree

1 file changed

+4
-4
lines changed

1 file changed

+4
-4
lines changed

src/execution/__tests__/stream-test.ts

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { assert, expect } from 'chai';
1+
import { assert } from 'chai';
22
import { describe, it } from 'mocha';
33

44
import { expectJSON } from '../../__testUtils__/expectJSON.js';
@@ -1422,9 +1422,8 @@ describe('Execute: stream directive', () => {
14221422
[Symbol.asyncIterator]: () => ({
14231423
next: () => {
14241424
if (requested) {
1425-
/* c8 ignore next 3 */
1426-
// Not reached, iterator should end immediately.
1427-
expect.fail('Not reached');
1425+
// Ignores further errors when filtered.
1426+
return Promise.reject(new Error('Oops'));
14281427
}
14291428
requested = true;
14301429
const friend = friends[0];
@@ -1438,6 +1437,7 @@ describe('Execute: stream directive', () => {
14381437
},
14391438
return: () => {
14401439
returned = true;
1440+
// Ignores errors from return.
14411441
return Promise.reject(new Error('Oops'));
14421442
},
14431443
}),

0 commit comments

Comments
 (0)