Gathering detailed insights and metrics for apollo-client-mock
Gathering detailed insights and metrics for apollo-client-mock
Gathering detailed insights and metrics for apollo-client-mock
Gathering detailed insights and metrics for apollo-client-mock
mock-apollo-client
Library to help unit testing when using apollo-client
@graphitation/apollo-mock-client
An Apollo Client that allows mocking of payloads in response to operations, rather than having to provide them all upfront.
wildcard-mock-link
apollo client mocking
@apollo-mock-operations/core
Core module utilized in intercepting and mocking requests for Apollo client
npm install apollo-client-mock
Typescript
Module System
Node Version
NPM Version
47.5
Supply Chain
84.2
Quality
73.3
Maintenance
100
Vulnerability
99.6
License
JavaScript (79.57%)
HTML (16%)
CSS (4.43%)
Total Downloads
139,431
Last Day
12
Last Week
70
Last Month
597
Last Year
8,386
MIT License
18 Stars
25 Commits
8 Forks
1 Watchers
1 Branches
2 Contributors
Updated on Apr 08, 2021
Minified
Minified + Gzipped
Latest Version
0.0.9
Package Id
apollo-client-mock@0.0.9
Unpacked Size
9.82 kB
Size
3.98 kB
File Count
5
NPM Version
6.0.1
Node Version
10.1.0
Cumulative downloads
Total Downloads
Last Day
0%
12
Compared to previous day
Last Week
-29.3%
70
Compared to previous week
Last Month
-21.9%
597
Compared to previous month
Last Year
-46.7%
8,386
Compared to previous year
Easily mock your apollo client for testing. It uses Apollo Link Schema under the surface
1$ npm install --save-dev apollo-client-mock
To setup Apollo mock client you need to import your schema in as well as your mock resolvers. Then you can setup your client with these two arguments which will then return a createClient
function which you can create a mockedClient for each test. createClient
can optionally take a new set of resolvers that can overwrite your defaults
1import typeDefs from '../link/to/schema' 2import setupClient from 'apollo-client-mock' 3 4const defaultMocks = { 5 Query: () => ({ 6 nodes: () => [] 7 //...other queries 8 }), 9 Mutation: () => ({ 10 getDomainState: (_, { name }, context) => { 11 return { 12 name, 13 state: 'Open' 14 } 15 } 16 //...other mutations 17 }) 18} 19 20const createClient = setupClient(defaultMocks, typeDefs) 21 22export default createClient
1//Test file 2 3import React from 'react' 4import { 5 render 6} from 'react-testing-library' 7 8import { ApolloProvider } from 'react-apollo' 9import createClient from '../testing-utils/mockedClient' 10 11import CheckAvailabilityContainer from '../CheckAvailability' 12 13afterEach(cleanup) 14 15test('should call resolver without blowing up', () => { 16 const { getByText, container } = render( 17 <ApolloProvider client={createClient()}> 18 <CheckAvailabilityContainer /> 19 </ApolloProvider> 20 ) 21 22 //the rest of your test 23}
The following example shows you can overwrite each resolver per test. This is useful if you want to setup a spy for your resolver function to ensure it has been called. This is particularly useful if your component just makes a mutation but does not actually show the result of the state change in the component.
1test('should call resolver without blowing up', () => { 2 const getDomainState = jest.fn() 3 const resolverOverwrites = { 4 Mutation: () => ({ 5 getDomainState 6 }) 7 } 8 const { getByText, container } = renderIntoDocument( 9 <ApolloProvider client={createClient(resolverOverwrites)}> 10 <CheckAvailabilityContainer /> 11 </ApolloProvider> 12 ) 13 14 const submitButton = getByText('Check Availability') 15 const form = container.querySelector('form') 16 const input = form.querySelector('input') 17 input.value = 'vitalik.eth' 18 Simulate.change(input) 19 submitButton.click() 20 expect(getDomainState).toHaveBeenCalledTimes(1) 21})
No vulnerabilities found.
Reason
no binaries found in the repo
Reason
license file detected
Details
Reason
0 commit(s) and 0 issue activity found in the last 90 days -- score normalized to 0
Reason
Found 2/23 approved changesets -- score normalized to 0
Reason
no effort to earn an OpenSSF best practices badge detected
Reason
security policy file not detected
Details
Reason
project is not fuzzed
Details
Reason
branch protection not enabled on development/release branches
Details
Reason
SAST tool is not run on all commits -- score normalized to 0
Details
Reason
147 existing vulnerabilities detected
Details
Score
Last Scanned on 2025-06-30
The Open Source Security Foundation is a cross-industry collaboration to improve the security of open source software (OSS). The Scorecard provides security health metrics for open source projects.
Learn More