# Conditional test

**URL:** <https://community.postman.com/t/conditional-test/11641>\
**Category:** Help Hub\
**Tags:** tests\
**Created:** [April 1, 2020, 8:38am UTC](https://community.postman.com/t/conditional-test/11641 "2020-04-01T08:38:51Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![vinai.bw](https://avatars.discourse-cdn.com/v4/letter/v/ac91a4/32.png) [@vinai.bw](https://community.postman.com/u/vinai.bw)\
**Post date:** [April 1, 2020, 8:38am UTC](https://community.postman.com/t/conditional-test/11641/1 "2020-04-01T08:38:51Z")

</div>

I am a novice to both javascript and Postman I have written a conditional class for test execution of tests but it’s not giving expected results. Can some help me here

```
pm.test("Check the status code",function(){
    if(pm.response.status !== 200)
    {
        postman.setNextRequest("GetItem")
    }
    else
    {
        console.log("Check authentication")
    }
});

```

I am expecting to this to fail but it’s not

---

<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:** [April 1, 2020, 10:25am UTC](https://community.postman.com/t/conditional-test/11641/2 "2020-04-01T10:25:38Z")

</div>

Hey @vinai.bw,

Welcome to the community! 👋

In order for it to fail, it would need a `pm.expect()` statement to fail against. If it doesn’t have one, it will always ‘Pass’.

For example:

```
pm.test("Response time is less than 200ms", function () {
    pm.expect(pm.response.responseTime).to.be.below(200);
});  

```

If the response time was _above_ 200ms, the test would fail.

* * *

I’m not really sure of the full context here but you could try something like this:

```
pm.test("Check the status code", function(){
    if(pm.response.code !== 200)
    {
        pm.expect.fail("Status Code is not 200")
        postman.setNextRequest("GetItem")
    }
    else
    {
        pm.response.to.have.status(200);
        console.log("Check authentication")
    }
});

```

More information about tests on our learning site:

[https://learning.postman.com/docs/postman/scripts/test-scripts/](https://learning.postman.com/docs/postman/scripts/test-scripts/)
