# Why do I get an assertion error about status code?

**URL:** <https://community.postman.com/t/why-do-i-get-an-assertion-error-about-status-code/59358>\
**Category:** Help Hub\
**Tags:** tests\
**Created:** [March 28, 2024, 9:40pm UTC](https://community.postman.com/t/why-do-i-get-an-assertion-error-about-status-code/59358 "2024-03-28T21:40:45Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![ameenjafferie](https://avatars.discourse-cdn.com/v4/letter/a/54ee81/32.png) [@ameenjafferie](https://community.postman.com/u/ameenjafferie)\
**Post date:** [March 28, 2024, 9:40pm UTC](https://community.postman.com/t/why-do-i-get-an-assertion-error-about-status-code/59358/1 "2024-03-28T21:40:45Z")

</div>

I am getting the following errors:  
`There was an error in evaluating the test script: AssertionError: expected response to have status code 200 but got 409`

I thought the following lines would cover that scenario?

```auto
if (pm.response.to.have.status(200)){
    pm.test("Status code is 200", function () {
        pm.response.to.have.status(200);
    })
} else if (pm.response.to.have.status(409)){
    pm.test("Status code is 409", function () {
        pm.response.to.have.status(409);
    })
}
```

---

<div class="post-metadata">

**Author:** ![danny-dainton](https://sea2.discourse-cdn.com/getpostman/user_avatar/community.postman.com/danny-dainton/32/29401_2.png) [@danny-dainton](https://community.postman.com/u/danny-dainton)\
**Post date:** [March 28, 2024, 10:21pm UTC](https://community.postman.com/t/why-do-i-get-an-assertion-error-about-status-code/59358/2 "2024-03-28T22:21:09Z")

</div>

Hey @ameenjafferie 👋

You’ve used a Postman helper as your conditional check. I think you’re probably trying to do something like this:

```auto
if (pm.response.code === 200){
    pm.test("Status code is 200", function () {
        pm.response.to.have.status(200);
    })
} else if (pm.response.code === 409){
    pm.test("Status code is 409", function () {
        pm.response.to.have.status(409);
    })
}

```

---

<div class="post-metadata">

**Author:** ![ameenjafferie](https://avatars.discourse-cdn.com/v4/letter/a/54ee81/32.png) [@ameenjafferie](https://community.postman.com/u/ameenjafferie)\
**Post date:** [April 11, 2024, 9:28pm UTC](https://community.postman.com/t/why-do-i-get-an-assertion-error-about-status-code/59358/3 "2024-04-11T21:28:45Z")

</div>

Thank you - worked like magic!

---

<div class="post-metadata">

**Author:** ![system](https://sea2.discourse-cdn.com/getpostman/user_avatar/community.postman.com/system/32/29796_2.png) [@system](https://community.postman.com/u/system)\
**Post date:** [April 14, 2024, 9:28pm UTC](https://community.postman.com/t/why-do-i-get-an-assertion-error-about-status-code/59358/4 "2024-04-14T21:28:47Z")

</div>

Closed on April 14, 2024, 9:28pm UTC

This topic was automatically closed 3 days after the last reply. New replies are no longer allowed.
