|
1 | 1 | import { assert, expect } from 'chai';
|
2 | 2 | import { describe, it } from 'mocha';
|
3 | 3 |
|
| 4 | +import { expectEqualPromisesOrValues } from '../../__testUtils__/expectEqualPromisesOrValues'; |
4 | 5 | import { expectJSON } from '../../__testUtils__/expectJSON';
|
| 6 | +import { expectPromise } from '../../__testUtils__/expectPromise'; |
5 | 7 | import { resolveOnNextTick } from '../../__testUtils__/resolveOnNextTick';
|
6 | 8 |
|
7 | 9 | import { isAsyncIterable } from '../../jsutils/isAsyncIterable';
|
@@ -125,49 +127,6 @@ function createSubscription(pubsub: SimplePubSub<Email>) {
|
125 | 127 | return subscribe({ schema: emailSchema, document, rootValue: data });
|
126 | 128 | }
|
127 | 129 |
|
128 |
| -// TODO: consider adding this method to testUtils (with tests) |
129 |
| -function expectPromise(maybePromise: unknown) { |
130 |
| - assert(isPromise(maybePromise)); |
131 |
| - |
132 |
| - return { |
133 |
| - toResolve() { |
134 |
| - return maybePromise; |
135 |
| - }, |
136 |
| - async toRejectWith(message: string) { |
137 |
| - let caughtError: Error; |
138 |
| - |
139 |
| - try { |
140 |
| - /* c8 ignore next 2 */ |
141 |
| - await maybePromise; |
142 |
| - expect.fail('promise should have thrown but did not'); |
143 |
| - } catch (error) { |
144 |
| - caughtError = error; |
145 |
| - } |
146 |
| - |
147 |
| - expect(caughtError).to.be.an.instanceOf(Error); |
148 |
| - expect(caughtError).to.have.property('message', message); |
149 |
| - }, |
150 |
| - }; |
151 |
| -} |
152 |
| - |
153 |
| -// TODO: consider adding this method to testUtils (with tests) |
154 |
| -function expectEqualPromisesOrValues<T>( |
155 |
| - value1: PromiseOrValue<T>, |
156 |
| - value2: PromiseOrValue<T>, |
157 |
| -): PromiseOrValue<T> { |
158 |
| - if (isPromise(value1)) { |
159 |
| - assert(isPromise(value2)); |
160 |
| - return Promise.all([value1, value2]).then((resolved) => { |
161 |
| - expectJSON(resolved[1]).toDeepEqual(resolved[0]); |
162 |
| - return resolved[0]; |
163 |
| - }); |
164 |
| - } |
165 |
| - |
166 |
| - assert(!isPromise(value2)); |
167 |
| - expectJSON(value2).toDeepEqual(value1); |
168 |
| - return value1; |
169 |
| -} |
170 |
| - |
171 | 130 | const DummyQueryType = new GraphQLObjectType({
|
172 | 131 | name: 'Query',
|
173 | 132 | fields: {
|
@@ -195,10 +154,10 @@ function subscribeWithBadFn(
|
195 | 154 | function subscribeWithBadArgs(
|
196 | 155 | args: ExecutionArgs,
|
197 | 156 | ): PromiseOrValue<ExecutionResult | AsyncIterable<unknown>> {
|
198 |
| - return expectEqualPromisesOrValues( |
| 157 | + return expectEqualPromisesOrValues([ |
199 | 158 | subscribe(args),
|
200 | 159 | createSourceEventStream(args),
|
201 |
| - ); |
| 160 | + ]); |
202 | 161 | }
|
203 | 162 |
|
204 | 163 | /* eslint-disable @typescript-eslint/require-await */
|
|
0 commit comments