node.js - 所有测试都通过时测试套件失败:Jest & Supertest with GraphQL request
问题描述
我有以下帮助函数用于在 Jest 中发送我的 GraphQL 请求:
export async function graphQLBase(requestString: string, variables?: any) {
const sendRequest: TestGQLRequest = { query: requestString, variables }
return request(app)
.post('/spikeql')
.set('Authorization', `Bearer ${mockToken}`)
.send(sendRequest)
.expect('Content-Type', /json/)
.expect(200)
}
然后我有以下测试套件:
const createPostMutation = `mutation Mutation($postInfo: PostCreationInfo) {
createPost(postInfo: $postInfo) {
description
}
}`
describe('Query GQL: Posts', () => {
beforeAll(async () => {
await mongoConnect()
})
describe('create post', () => {
test('It should create a text post', async () => {
const testTextPostDesc = 'Test post via supertest unit test'
const createPostVariables = {
postInfo: {
description: testTextPostDesc
}
}
const { body } = await graphQLBase(createPostMutation, createPostVariables)
// const { description, createdBy } = body.data.createPost
// expect(description).toBeDefined()
// expect(createdBy).toBeDefined()
// expect(description === testTextPostDesc)
expect(1)
})
})
afterAll(async () => {
await mongoDisconnect()
})
})
我的测试套件中出现以下错误,而位于测试套件中的测试完美通过。我还添加了一个日志来查看突变是否返回任何值,并且还可以确认它正确地将资源添加到数据库中。
使用 Supertest 时是否需要额外考虑突变?到目前为止,查询工作正常。
解决方案
推荐阅读
- loops - 6800 汇编代码 如何编辑循环的最后一个字符?
- jquery - 将值从一个 html 表单传递到另一个
- vue.js - (使用 npm 包时)无法挂载组件:未定义模板或渲染函数
- angular - Angular 10:我应该取消订阅 ngOnDestroy 中 valueChanges Observable 的订阅吗?
- ios - HealthKit 方法的单元测试
- java - SpringRunner.class 无法解析为类型
- javascript - 加载新的 Turbo Frame 时如何执行 JavaScript
- sql-server - VB .NET,我希望用户名和密码来自数据库,并在 3 次失败尝试后关闭程序
- javascript - } 预期在 ForEach 循环中
- python - Python argparse.FileType('w') 只创建空文件