Matt Abrams
02/20/2019, 4:10 AMprisma
on context
. It might simply come down to needing to @ts-ignore
every use of a mock prisma seeing as the type definition is pretty huge to replicate an instance of. Thanks!albinekb
02/20/2019, 7:45 AMMatt Abrams
02/20/2019, 7:59 AMVittorio Adamo
02/20/2019, 8:25 AMVittorio Adamo
02/20/2019, 8:26 AMVittorio Adamo
02/20/2019, 8:31 AMimport { graphql } from 'graphql'
import { makePrismaSchema } from 'nexus-prisma'
import datamodelInfo from '../types/generated/nexus-prisma'
import * as allTypes from '../schema'
interface Options {
context?: {
db?: any
locale?: any
request?: any
}
variables?: any
}
export const schema = makePrismaSchema({
types: allTypes,
prisma: {
datamodelInfo,
client: jest.fn(),
},
} as any)
// Nice little helper function for tests
export const deathStar = (
query: any,
{ context, variables }: Options = {},
root = undefined
) => {
return graphql(
schema,
query,
root,
{
...context,
},
variables
)
}
resource.spec.ts
import { deathStar } from 'test-utils'
test("it hasn't activeSpeedFactory", async () => {
const query = `
query fetchSpeedy {
speedfactory {
id
}
}
`
const context = () => ({
db: {
configuration: () => ({
activeSpeedFactory: () => null,
}),
},
locale: <http://Locales.US|Locales.US>,
})
expect.hasAssertions()
const { data, errors } = await deathStar(query, {
context: context(),
})
expect(errors[0].message).toBe(
`There isn't a valid activeSpeedfactory for ${
<http://Locales.US|Locales.US>
}, check your configuration!`
)
expect(errors).toMatchSnapshot()
Harshit
02/20/2019, 9:10 AM