Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/apache-spark/5.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Node Express JEST Supertest放置和删除端点返回405“;“不允许使用方法”;_Express_Jestjs_Supertest - Fatal编程技术网

Node Express JEST Supertest放置和删除端点返回405“;“不允许使用方法”;

Node Express JEST Supertest放置和删除端点返回405“;“不允许使用方法”;,express,jestjs,supertest,Express,Jestjs,Supertest,我正在使用Express和suppertest在节点上运行一个简单的测试。共有10个测试,其中POST和GET测试运行良好(前6个测试)。其他四个,已经放置和删除,返回405“方法不允许”。这是我的代码: test('Should login existing user', async () => { await request(app) .post('/api/auth') .send({ email: userOne.email

我正在使用Express和suppertest在节点上运行一个简单的测试。共有10个测试,其中POST和GET测试运行良好(前6个测试)。其他四个,已经放置和删除,返回405“方法不允许”。这是我的代码:

test('Should login existing user', async () => {
  await request(app)
        .post('/api/auth')
        .send({ 
          email: userOne.email,
          password: userOne.password
        })
        .expect(200);
});


test('Should NOT login nonexisting user', async () => {
  await request(app)
        .post('/api/auth')
        .send({ 
          email: userThree.email,
          password: userThree.password
        })
        .expect(400);
});


test('Should get profile for authenticated user', async () => {
  await request(app)
        .get('/api/auth')
        .set('x-auth-token', userOne.token)
        .expect(200)
});


test('Should NOT get profile for unauthenticated user', async () => {
  await request(app)
        .get('/api/auth')
        .expect(401)
});


test('Should create a new user', async () => {
  await request(app)
        .post('/api/person')
        .set('x-auth-token', userOne.token)
        .send({ ...userTwo })
        .expect(201);
});


test('Should NOT create a new user', async () => {
  await request(app)
        .post('/api/person')
        .send({ ...userTwo })
        .expect(401);
});


test('Should update user for autheticated user', async () => {
  await request(app)
        .put('api/person/2')
        .set('x-auth-token', userOne.token)
        .send({ role: 1})
        .expect(200)
});


test('Should NOT update user for unauthenticated user', async () => {
  await request(app)
        .put('api/person/2')
        .send({ role: 1})
        .expect(401)
});


test('Should delete user for autheticated user', async () => {
  await request(app)
        .delete('api/person/2')
        .set('x-auth-token', userOne.token)
        .send()
        .expect(200)
});


test('Should NOT delete user for unauthenticated user', async () => {
  await request(app)
        .delete('api/person/2')
        .expect(401)
});

正如我上面所说的,前六名无论是有认证还是没有认证都非常出色。具有PUT和DELETE请求的底部4返回405“不允许使用方法”。与邮递员测试相同的路线我没有遇到任何问题。DELETE和POST方法都按预期工作。有人知道我做错了什么吗?我忽略了什么?谢谢您的帮助。

删除和放置方法没有问题。原因是一个简单的输入错误(在'api/person/2'调用前面缺少一个/a)。不幸的是,这种情况只发生在DELETE和PUT方法中,这使得调试需要更长的时间来考虑方法的问题。这个bug要简单得多。路径不正确