应用程序中的博客"/>
我无法通过 axios 删除我的 express 应用程序中的博客
第一次测试:- 检查博客是否存在于数据库中 第二次测试:- 尝试删除博客
describe( "delete request", () => {
test.only('checking whether the blog exists' , async () => {
const blogs = await blogsInDb() //asynchronous function to fetch all the blogs in the db
const blogToBeDeleted = blogs[0]
const blogToBeDeletedId = blogToBeDeleted.id
await api
.get(`/api/blogs/${blogToBeDeletedId}`)
.expect(200)
.expect('Content-Type', /application\/json/)
})
test.only('deleting blogs' , async () => {
const blogsInStart = await blogsInDb() //asynchronous function to fetch all the blogs in the db
const blogToBeDeleted = blogsInStart[0]
const blogToBeDeletedId = blogToBeDeleted.id
await api
.delete(`/api/blogs/${blogToBeDeletedId}`)
.send(blogToBeDeleted)
.expect(204)
})
})
所以,如果第一个测试通过,那应该意味着博客存在于数据库中,第二个测试应该运行得很好。最重要的是,它不应该告诉我“找不到 404”。但是
delete request
√ checking whether the blog exists (614 ms)
× deleting blogs (51 ms)
● delete request › deleting blogs
expected 204 "No Content", got 404 "Not Found"
140 | .delete(`/api/blogs/${blogToBeDeletedId}`)
141 | .send(blogToBeDeleted)
> 142 | .expect(204)
| ^
at Object.expect (tests/blogs_api.test.js:142:14)
如果有人能帮忙,那就太好了
尝试删除我的 Express 应用程序中的博客。 期待 204 状态。 找不到 404。
回答如下:更多推荐
我无法通过 axios 删除我的 express 应用程序中的博客
发布评论