Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

mock-apollo-client

Package Overview
Dependencies
Maintainers
1
Versions
15
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

mock-apollo-client - npm Package Compare versions

Comparing version 0.2.0 to 0.3.0

2

dist/index.d.ts

@@ -1,1 +0,1 @@

export { createMockClient, MockApolloClient, RequestHandler } from './mockClient';
export * from './mockClient';
"use strict";
function __export(m) {
for (var p in m) if (!exports.hasOwnProperty(p)) exports[p] = m[p];
}
Object.defineProperty(exports, "__esModule", { value: true });
var mockClient_1 = require("./mockClient");
exports.createMockClient = mockClient_1.createMockClient;
__export(require("./mockClient"));

@@ -1,2 +0,2 @@

import ApolloClient from 'apollo-client';
import ApolloClient, { ApolloClientOptions } from 'apollo-client';
import { NormalizedCacheObject } from 'apollo-cache-inmemory';

@@ -12,2 +12,3 @@ import { DocumentNode } from 'apollo-link';

};
export declare const createMockClient: () => MockApolloClient;
export declare type MockApolloClientOptions = Partial<Omit<ApolloClientOptions<NormalizedCacheObject>, 'link'>> | undefined;
export declare const createMockClient: (options?: MockApolloClientOptions) => MockApolloClient;
"use strict";
var __assign = (this && this.__assign) || function () {
__assign = Object.assign || function(t) {
for (var s, i = 1, n = arguments.length; i < n; i++) {
s = arguments[i];
for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p))
t[p] = s[p];
}
return t;
};
return __assign.apply(this, arguments);
};
var __importDefault = (this && this.__importDefault) || function (mod) {

@@ -9,10 +20,11 @@ return (mod && mod.__esModule) ? mod : { "default": mod };

var mockLink_1 = require("./mockLink");
exports.createMockClient = function () {
exports.createMockClient = function (options) {
var _a;
if ((_a = options) === null || _a === void 0 ? void 0 : _a.link) {
throw new Error('Providing link to use is not supported.');
}
var mockLink = new mockLink_1.MockLink();
var client = new apollo_client_1.default({
cache: new apollo_cache_inmemory_1.InMemoryCache({
var client = new apollo_client_1.default(__assign(__assign({ cache: new apollo_cache_inmemory_1.InMemoryCache({
addTypename: false,
}),
link: mockLink,
});
}) }, options), { link: mockLink }));
var mockMethods = {

@@ -19,0 +31,0 @@ setRequestHandler: mockLink.setRequestHandler.bind(mockLink),

{
"name": "mock-apollo-client",
"version": "0.2.0",
"version": "0.3.0",
"description": "Library to help unit testing when using apollo-client",

@@ -33,3 +33,3 @@ "main": "dist/index.js",

"@types/graphql": "^14.2.3",
"@types/jest": "^24.0.17",
"@types/jest": "^25.1.4",
"apollo-cache-inmemory": "^1.6.2",

@@ -39,5 +39,5 @@ "apollo-client": "^2.6.3",

"graphql-tag": "^2.10.1",
"jest": "^24.8.0",
"ts-jest": "^24.0.2",
"typescript": "^3.5.3"
"jest": "^25.1.0",
"ts-jest": "^25.2.1",
"typescript": "^3.8.3"
},

@@ -44,0 +44,0 @@ "peerDependencies": {

@@ -115,3 +115,3 @@ # Mock Apollo Client

mockApolloClient.setRequestHandler(GET_DOG_QUERY, requestHandler);
mockApolloClient.setRequestHandler(GET_DOG_QUERY, queryHandler);

@@ -151,1 +151,16 @@ // ....

Mutations can be tested the same way that queries are, by using `setRequestHandler` and specifying a request handler for the mutation query.
### Specifying Apollo client options
The `createMockClient` method can be provided with the same constructor arguments that `ApolloClient` accepts which are used when instantiating the mock Apollo client.
For example, to specify the cache (and fragment matcher) that should be used:
```typescript
const cache = new InMemoryCache({
fragmentMatcher: myCustomFragmentMatcher,
});
const mockClient = createMockClient({ cache });
```
Note: it is not possible to specify the `link` to use as this is how Mock Apollo Client injects its behaviour.
SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc