【发布时间】:2019-02-22 14:52:51
【问题描述】:
我正在学习 graphql 并想为我的解析器进行单元测试(即获取“答案”的查询)。问题是我的解析器使用 mongoose 从幕后的 mongodb 查询数据,我不知道如何模拟这些电话。
谁能帮我解决这个问题?谢谢。
我的查询的解析器是这样的:
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 -->
}
【问题讨论】:
标签: node.js mongodb unit-testing mongoose graphql