# Pm.test not initialized inside pm.sendRequest

**URL:** <https://community.postman.com/t/pm-test-not-initialized-inside-pm-sendrequest/22013>\
**Category:** Help Hub\
**Tags:** tests\
**Created:** [March 28, 2021, 11:44pm UTC](https://community.postman.com/t/pm-test-not-initialized-inside-pm-sendrequest/22013 "2021-03-28T23:44:44Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![barakbs1](https://sea2.discourse-cdn.com/getpostman/user_avatar/community.postman.com/barakbs1/32/7855_2.png) [@barakbs1](https://community.postman.com/u/barakbs1)\
**Post date:** [March 28, 2021, 11:44pm UTC](https://community.postman.com/t/pm-test-not-initialized-inside-pm-sendrequest/22013/1 "2021-03-28T23:44:45Z")

</div>

Hi everyone, so I’m trying to use pm.test inside pm.sendRequest, and it appears that the pm.test isn’t initialized. Moreover, I’m trying to console.log the response, and yet again nothing happens (response, inside pm.sendRequest and outside of pm.test, isn’t printed to the console). Here is my code:

```
const passengersUrl = pm.variables.replaceIn("localhost:5000/Users/type=2&limit=20&page=1");
pm.sendRequest(passengersUrl), (error, response) => {
    if (error) {
        console.log(error);
    }

    pm.test("Get all drivers users route returns only drivers", () => {
        const responseJson = response.json();
        const usersArray = responseJson.data.users;
        usersArray.forEach(e => {
            for (const [key, value] of Object.entries(e)) {
                if (key == 'type') {
                    pm.expect(value).to.eql(1)
                }
            }
        })
    });
}

```

I was using the following documentation example: [https://learning.postman.com/docs/writing-scripts/script-references/postman-sandbox-api-reference/#sending-requests-from-scripts](https://learning.postman.com/docs/writing-scripts/script-references/postman-sandbox-api-reference/#sending-requests-from-scripts)

Any suggestions? 🤔

---

<div class="post-metadata">

**Author:** ![taehoshino](https://sea2.discourse-cdn.com/getpostman/user_avatar/community.postman.com/taehoshino/32/6608_2.png) [@taehoshino](https://community.postman.com/u/taehoshino)\
**Post date:** [March 29, 2021, 4:48am UTC](https://community.postman.com/t/pm-test-not-initialized-inside-pm-sendrequest/22013/2 "2021-03-29T04:48:15Z")

</div>

Hey @barakbs1 👋 Welcome to the Postman community 🎉

I think the bracket after `passengerUrl` is causing the issue. Try the following:

```
const passengersUrl = pm.variables.replaceIn("localhost:5000/Users/type=2&limit=20&page=1");
pm.sendRequest(passengersUrl, (error, response) => {
    if (error) {
    console.log(error);
    }

    pm.test("Get all drivers users route returns only drivers", () => {
        const responseJson = response.json();
        const usersArray = responseJson.data.users;
        usersArray.forEach(e => {
            for (const [key, value] of Object.entries(e)) {
                if (key == 'type') {
                    pm.expect(value).to.eql(1)
                }
            }
        })
    });
})
```

---

<div class="post-metadata">

**Author:** ![barakbs1](https://sea2.discourse-cdn.com/getpostman/user_avatar/community.postman.com/barakbs1/32/7855_2.png) [@barakbs1](https://community.postman.com/u/barakbs1)\
**Post date:** [March 29, 2021, 11:18pm UTC](https://community.postman.com/t/pm-test-not-initialized-inside-pm-sendrequest/22013/3 "2021-03-29T23:18:27Z")

</div>

Yes, that did the job! thank you very much!
