1

enter image description here

I am trying to validate the positive and negative test cases using response assertion, but it didn't give me the expected result.

I am trying to confirm the response using "pm.response.to.be.ok" to get the response as "200" an so on as listed in the screenshot, but it gives me error as

TypeError: Cannot read property 'to' of undefined

James Z
  • 12,209
  • 10
  • 24
  • 44
DEV QC
  • 21
  • 4

1 Answers1

0

The syntax in the tests are incorrect and that's why it's throwing an error, it should be something like this:

pm.test('Check the response', () => {
    pm.response.to.be.ok
    pm.response.to.have.body()
    pm.response.to.have.jsonBody()
})

https://learning.getpostman.com/docs/postman/scripts/postman_sandbox_api_reference/

Danny Dainton
  • 23,069
  • 6
  • 67
  • 80
  • hello, danny thanks for the solution. It works fine for "to.be.ok" but body and jsonBody(); are not giving result. – DEV QC Jun 11 '19 at 05:50
  • Not giving the result of what? Can you update your original question and provide more screen shots of the error and information about what you're doing. Saying 'It doesn't work" isn't very helpful. – Danny Dainton Jun 11 '19 at 10:51