Research
Security News
Quasar RAT Disguised as an npm Package for Detecting Vulnerabilities in Ethereum Smart Contracts
Socket researchers uncover a malicious npm package posing as a tool for detecting vulnerabilities in Etherium smart contracts.
apollo-client-mock
Advanced tools
Easily mock your apollo client for testing. It uses Apollo Link Schema under the surface
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
import typeDefs from '../link/to/schema'
import setupClient from 'apollo-mock-client'
const defaultMocks = {
Query: () => ({
nodes: () => []
//...other queries
}),
Mutation: () => ({
getDomainState: (_, { name }, context) => {
return {
name,
state: 'Open'
}
}
//...other mutations
})
}
const createClient = setupClient(defaultMocks, typeDefs)
export default createClient
//Test file
import React from 'react'
import {
render
} from 'react-testing-library'
import { ApolloProvider } from 'react-apollo'
import createClient from '../testing-utils/mockedClient'
import CheckAvailabilityContainer from '../CheckAvailability'
afterEach(cleanup)
test('should call resolver without blowing up', () => {
const { getByText, container } = render(
<ApolloProvider client={createClient()}>
<CheckAvailabilityContainer />
</ApolloProvider>
)
//the rest of your test
}
The following example shows you can overwrite each resolver per test
test('should call resolver without blowing up', () => {
const overwriteResolvers = {
Mutation: () => ({
getDomainState: (_, { name }, context) => {
return {
name,
state: 'Closed'
}
}
})
}
render(
<ApolloProvider client={createClient(overwriteResolvers)}>
<CheckAvailabilityContainer />
</ApolloProvider>
)
//the rest of your test
}
FAQs
Easily mock the Apollo client for your integration tests
The npm package apollo-client-mock receives a total of 142 weekly downloads. As such, apollo-client-mock popularity was classified as not popular.
We found that apollo-client-mock demonstrated a not healthy version release cadence and project activity because the last version was released a year ago. It has 1 open source maintainer collaborating on the project.
Did you know?
Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.
Research
Security News
Socket researchers uncover a malicious npm package posing as a tool for detecting vulnerabilities in Etherium smart contracts.
Security News
Research
A supply chain attack on Rspack's npm packages injected cryptomining malware, potentially impacting thousands of developers.
Research
Security News
Socket researchers discovered a malware campaign on npm delivering the Skuld infostealer via typosquatted packages, exposing sensitive data.