![Oracle Drags Its Feet in the JavaScript Trademark Dispute](https://cdn.sanity.io/images/cgdhsj6q/production/919c3b22c24f93884c548d60cbb338e819ff2435-1024x1024.webp?w=400&fit=max&auto=format)
Security News
Oracle Drags Its Feet in the JavaScript Trademark Dispute
Oracle seeks to dismiss fraud claims in the JavaScript trademark dispute, delaying the case and avoiding questions about its right to the name.
apollo-client-mock
Advanced tools
Easily mock your apollo client for testing. It uses Apollo Link Schema under the surface
$ 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
import typeDefs from '../link/to/schema'
import setupClient from 'apollo-client-mock'
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. 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.
test('should call resolver without blowing up', () => {
const getDomainState = jest.fn()
const resolverOverwrites = {
Mutation: () => ({
getDomainState
})
}
const { getByText, container } = renderIntoDocument(
<ApolloProvider client={createClient(resolverOverwrites)}>
<CheckAvailabilityContainer />
</ApolloProvider>
)
const submitButton = getByText('Check Availability')
const form = container.querySelector('form')
const input = form.querySelector('input')
input.value = 'vitalik.eth'
Simulate.change(input)
submitButton.click()
expect(getDomainState).toHaveBeenCalledTimes(1)
})
FAQs
Easily mock the Apollo client for your integration tests
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.
Security News
Oracle seeks to dismiss fraud claims in the JavaScript trademark dispute, delaying the case and avoiding questions about its right to the name.
Security News
The Linux Foundation is warning open source developers that compliance with global sanctions is mandatory, highlighting legal risks and restrictions on contributions.
Security News
Maven Central now validates Sigstore signatures, making it easier for developers to verify the provenance of Java packages.