Closed renegoretzka closed 5 years ago
@renegoretzka can you share me your test case pls?
user.resolvers.js
export default {
Query: {
getUser: async (root, { _id }) => {
try {
const user = await User.findById(_id)
return user
} catch (error) {
throw new Error(error)
}
}
}
test.js
import test from 'ava'
import gql from 'graphql-tag'
import EasyGraphQLTester from 'easygraphql-tester'
import { getSchema } from '../utils'
import { expect } from 'chai'
import UserResolvers from '@graphql/User/user.resolvers'
const UserSchema = getSchema('User', 'user')
const tester = new EasyGraphQLTester(UserSchema, UserResolvers)
test('Query: getUser', async t => {
const getUser = `
query GET_USER($_id: String!) {
getUser(_id: $_id) {
name
_id
}
}
`
const result = await tester.graphql(
getUser,
{},
{},
{
_id: '5c8d1b7c1b06595010cee8cd'
}
)
t.log(result)
}
The function getSchema() is just getting my right Schema. I use Ava for testing.
I'm trying to reproduce but it's not possible... do you have a better trace of the error?
Also, are you initializing the db connection before the tests?
Thats a great question! As the server (mongo) connection only runs when i start graphql, but in the test its not initialized. I am thinking about how to solve that it connects in the test environment.
Maybe try doing something like this
@renegoretzka can we close this issue?
I'm going to close this issue, in case that is needed we can open again 🙂
I have a problem testing async resolvers. I get an error which says "Promise returned by test never resolved".
How to get rid of it? I need async in the resolvers ofcourse.