From a6f75e60fe595efe5d3262c21df7398ed9e61ede Mon Sep 17 00:00:00 2001 From: Yaacov Rydzinski Date: Thu, 5 Jan 2023 18:21:00 +0200 Subject: [PATCH] polish: fix test 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. --- src/execution/__tests__/stream-test.ts | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/src/execution/__tests__/stream-test.ts b/src/execution/__tests__/stream-test.ts index aed5211ae1..cd9b9b3965 100644 --- a/src/execution/__tests__/stream-test.ts +++ b/src/execution/__tests__/stream-test.ts @@ -1,4 +1,4 @@ -import { assert, expect } from 'chai'; +import { assert } from 'chai'; import { describe, it } from 'mocha'; import { expectJSON } from '../../__testUtils__/expectJSON.js'; @@ -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]; @@ -1438,6 +1437,7 @@ describe('Execute: stream directive', () => { }, return: () => { returned = true; + // Ignores errors from return. return Promise.reject(new Error('Oops')); }, }),