Welcome to ShenZhenJia Knowledge Sharing Community for programmer and developer-Open, Learning and Share
menu search
person
Welcome To Ask or Share your Answers For Others

Categories

I am making jest tests for my project and I want to verify that the unique identifier of the blog posts is named id.

This is my mongoose db blog posts collection:

[
        {
          title: 'Breaking Ice',
          author: 'Mike Vasovsky',
          url: 'www.mikey.com',
          likes: 14,
          id: '5fe21b5931f6ae09d4cc58b6'
        }
]

My not finished part of the code:

test("verify id property name", async () => {
  const response = await api
    .get('/api/blogs')
  
  expect(...).toBeDefined("id")
})

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
thumb_up_alt 0 like thumb_down_alt 0 dislike
3.6k views
Welcome To Ask or Share your Answers For Others

1 Answer

When in doubt, use a boolean.

expect(response && response.every(blog => blog && blog.id)).toBe(true);

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
thumb_up_alt 0 like thumb_down_alt 0 dislike
Welcome to ShenZhenJia Knowledge Sharing Community for programmer and developer-Open, Learning and Share
...