# There was an error in evaluating the test script: AssertionError: expected null not to be null, instead of failing test

**URL:** <https://community.postman.com/t/there-was-an-error-in-evaluating-the-test-script-assertionerror-expected-null-not-to-be-null-instead-of-failing-test/13983>\
**Category:** Help Hub\
**Created:** [July 8, 2020, 11:21am UTC](https://community.postman.com/t/there-was-an-error-in-evaluating-the-test-script-assertionerror-expected-null-not-to-be-null-instead-of-failing-test/13983 "2020-07-08T11:21:53Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![handhito.gara](https://avatars.discourse-cdn.com/v4/letter/h/65b543/32.png) [@handhito.gara](https://community.postman.com/u/handhito.gara)\
**Post date:** [July 8, 2020, 11:21am UTC](https://community.postman.com/t/there-was-an-error-in-evaluating-the-test-script-assertionerror-expected-null-not-to-be-null-instead-of-failing-test/13983/1 "2020-07-08T11:21:53Z")

</div>

Hello, I’m currently learning test using Postman and I’m not an expert with Javascript. I am trying to create a function to test, but using it in pm.test throws error instead of failing the test case:

> There was an error in evaluating the test script: AssertionError: expected null not to be null

Below is the test that throws AssertionError:

```
var jsonData = pm.response.json();
var items = jsonData.data.items;

function checkValues(object) {
    for (const value of Object.values(object)) {
        pm.expect(value).to.not.be.null;
    };
};

items.forEach((item) => pm.test("item values are not null", checkValues(item)));

```

but if I don’t define a separate function, it fails the test as expected:

```
var jsonData = pm.response.json();
var items = jsonData.data.items;

items.forEach((item) => pm.test("item values are not null", function() {
    for (const value of Object.values(item)) {
        pm.expect(value).to.not.be.null;
    };
}));

```

Can someone help me and explain what should I do if I need that separate function so that I can reuse it? Thank you.

---

<div class="post-metadata">

**Author:** ![handhito.gara](https://avatars.discourse-cdn.com/v4/letter/h/65b543/32.png) [@handhito.gara](https://community.postman.com/u/handhito.gara)\
**Post date:** [July 15, 2020, 6:38am UTC](https://community.postman.com/t/there-was-an-error-in-evaluating-the-test-script-assertionerror-expected-null-not-to-be-null-instead-of-failing-test/13983/2 "2020-07-15T06:38:47Z")

</div>

figured it out

```
var jsonData = pm.response.json();
var items = jsonData.data.items;

function checkValues(object) {
    for (const value of Object.values(object)) {
        pm.expect(value).to.not.be.null;
    };
};

items.forEach((item) => pm.test("item values are not null", function() {
    checkValues(item);
}));
```
