我无法通过 axios 删除我的 express 应用程序中的博客

编程入门 行业动态 更新时间:2024-10-09 03:18:48

我无法通过 axios 删除我的 express <a href=https://www.elefans.com/category/jswz/34/1771452.html style=应用程序中的博客"/>

我无法通过 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 应用程序中的博客

本文发布于:2024-05-13 15:54:27,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1759956.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:应用程序   博客   axios   express

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!