ReferenceError: document is not defined

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?