使用Jest测试节点“ Post”返回错误

时间:2019-04-30 09:50:07

标签: node.js jestjs

当我尝试用开玩笑的方式测试我的node.js代码时,它给我一个“错误请求”错误,但我仍然可以手动将一些内容发布到我的数据库中

我应该如何解决此问题?

const request = require('supertest')
const app = require('../src/app')

test('should sign up a new user' , async() =>{
    await request(app).post('/users').send({
        name : 'jordy',
        email : 'jordy@example.com',
        password : '12345678'
    }).expect(201)
})

输出:

 PASS  test/math.test.js
 FAIL  test/user.test.js
  ● should sign up a new user

expected 201 "Created", got 400 "Bad Request"

  at Test.Object.<anonymous>.Test._assertStatus (node_modules/supertest/lib/test.js:268:12)
  at Test.Object.<anonymous>.Test._assertFunction (node_modules/supertest/lib/test.js:283:11)
  at Test.Object.<anonymous>.Test.assert (node_modules/supertest/lib/test.js:173:18)
  at Server.localAssert (node_modules/supertest/lib/test.js:131:12)

Test Suites: 1 failed, 1 passed, 2 total
Tests:       1 failed, 4 passed, 5 total
Snapshots:   0 total
Time:        4.36s, estimated 11s
Ran all test suites related to changed files.

Watch Usage: Press w to show more.

0 个答案:

没有答案