@zendesk/laika
Version:
Test, mock, intercept and modify Apollo Client's operations — in both browser and unit tests!
36 lines • 1.42 kB
JavaScript
import { ApolloClient, ApolloLink, execute, InMemoryCache, Observable, } from '@apollo/client/core';
// eslint-disable-next-line @typescript-eslint/no-explicit-any
export const onNextTick = (action) => new Promise((resolve, reject) => {
setTimeout(() => {
try {
resolve(action());
}
catch (error) {
reject(error);
}
});
});
const testClient = new ApolloClient({
cache: new InMemoryCache(),
link: ApolloLink.empty(),
});
const executeWithOptionalContext = execute;
export const executeLink = (link, request) =>
// Apollo Client 4 requires an explicit client in the execute context, while
// Apollo Client 3 still uses the two-argument signature.
executeWithOptionalContext.length >= 3
? executeWithOptionalContext(link, request, { client: testClient })
: executeWithOptionalContext(link, request);
export const observableOf = (...values) => new Observable((observer) => {
var _a;
values.forEach((value) => {
var _a;
(_a = observer.next) === null || _a === void 0 ? void 0 : _a.call(observer, value);
});
(_a = observer.complete) === null || _a === void 0 ? void 0 : _a.call(observer);
});
export const observableError = (error) => new Observable((observer) => {
var _a;
(_a = observer.error) === null || _a === void 0 ? void 0 : _a.call(observer, error);
});
//# sourceMappingURL=testUtils.js.map