# ReferenceError: document is not defined

**URL:** <https://community.postman.com/t/referenceerror-document-is-not-defined/4701>\
**Category:** Help Hub\
**Tags:** tests\
**Created:** [March 26, 2019, 6:25am UTC](https://community.postman.com/t/referenceerror-document-is-not-defined/4701 "2019-03-26T06:25:53Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![rajshrees](https://avatars.discourse-cdn.com/v4/letter/r/ee59a6/32.png) [@rajshrees](https://community.postman.com/u/rajshrees)\
**Post date:** [March 26, 2019, 6:25am UTC](https://community.postman.com/t/referenceerror-document-is-not-defined/4701/1 "2019-03-26T06:25:54Z")

</div>

Hello I want to verify the section type which has “OutletContent” should have OutletCodes in “sectionOutlets” attribute.

It’s a GET request.

Hence I have written below script in “tests”:

> ```
> var jsonData = JSON.parse(responseBody)
> var i
> 
> //Extract out the sections array from the response that was recevied
> sections = _.get(jsonData, 'responses[0].getSectionsCategoriesItems.content.sections');
> 
> //Run the for loop only over the items of the section, i.e uptil the section.length
> var result;
> for (i=0; i<sections.length; i++)
> {
> var sectionType = _.get(sections, `${i}.type`); //safe extraction
> if (sectionType === "OutletContent") 
> {
> var sectionOutletsCode = _.get(sections, `${i}.sectionOutlets`);
> if (sectionOutletsCode != "NULL")
> {
> document.write(sectionOutletsCode);
> result = true;
> }
> }
> else
> result = false;
> }
> 
> if (result === true)
> console.log("Test case Passed - Outlet Content Type of section is available with the outlets.")
> else
> console.log("Test case Failed - Outlet Content Type of section is not available with the outlets.")
> 
> ```

It’s giving me an error as  
**`There was an error in evaluating the test script: ReferenceError: document is not defined`**

Could you please help to understand why I am getting this error?

---

<div class="post-metadata">

**Author:** ![raj.negi](https://avatars.discourse-cdn.com/v4/letter/r/a87d85/32.png) [@raj.negi](https://community.postman.com/u/raj.negi)\
**Post date:** [October 21, 2020, 10:44am UTC](https://community.postman.com/t/referenceerror-document-is-not-defined/4701/2 "2020-10-21T10:44:45Z")

</div>

Do you able to resolve this issue?

---

<div class="post-metadata">

**Author:** ![allenheltondev](https://sea2.discourse-cdn.com/getpostman/user_avatar/community.postman.com/allenheltondev/32/31738_2.png) [@allenheltondev](https://community.postman.com/u/allenheltondev)\
**Post date:** [October 21, 2020, 1:47pm UTC](https://community.postman.com/t/referenceerror-document-is-not-defined/4701/3 "2020-10-21T13:47:38Z")

</div>

Hey @raj.negi, are you seeing something similar?

This type of error happens when you use a variable/method that doesn’t exist.

If you are having a similar problem, can you post your test script here and we can walk through it?
