I am learning graphql and want to do the unit testing for my resolver ( i.e. the query to get "answers").The problem is my resolver use mongoose to query data from mongodb behind the scene and I dont know how to mock these calls.
Could anyone help me with this ? Thank you.
The resolver for my query is sth like this:
const { Book, Author } = require('../models')
module.exports = {
answers: async ( parent, { searchText } ) => {
let authors = null;
let books = null;
try {
authors = await Author.find({});
books = await Book.find({});
return getAnswers(authors,books, searchText);
}catch (err) {
console.log(err);
}
return null;
}
}
function getAnswers(books,authors,text) {
<!-- process data here -->
}