# AssertionError: object tested must be an array, a map, an object, a set, a string, or a weakset, but number given

**URL:** <https://community.postman.com/t/assertionerror-object-tested-must-be-an-array-a-map-an-object-a-set-a-string-or-a-weakset-but-number-given/16924>\
**Category:** Help Hub\
**Created:** [October 20, 2020, 9:04am UTC](https://community.postman.com/t/assertionerror-object-tested-must-be-an-array-a-map-an-object-a-set-a-string-or-a-weakset-but-number-given/16924 "2020-10-20T09:04:18Z")\
**Posts on this page:** 19\
**Page:** 1

<div class="post-metadata">

**Author:** ![aakashjain8693](https://avatars.discourse-cdn.com/v4/letter/a/7c8e57/32.png) [@aakashjain8693](https://community.postman.com/u/aakashjain8693)\
**Post date:** [October 20, 2020, 9:04am UTC](https://community.postman.com/t/assertionerror-object-tested-must-be-an-array-a-map-an-object-a-set-a-string-or-a-weakset-but-number-given/16924/1 "2020-10-20T09:04:18Z")

</div>

Hi Team,  
Firstly I tried my best and all possibilities but not sure how I can resolve this issue.

So basically I am verifying API response through .csv file.  
My.csv file data header and my script looks fine but no idea why below error appear:  
 ![image](https://us1.discourse-cdn.com/getpostman/original/3X/3/4/34f870f254fc6443f9a9936f48d4d4636b3e2f0d.png)  
“AssertionError: object tested must be an array, a map, an object, a set, a string, or a weakset, but number given”

Step to reproduce:

1. Hit the API
2. Get the response:  
{  
“earnings”: {  
“commissionLastWeek”: {  
“amount”: 13490064.0000046,  
“currencyCode”: “USD”,  
“changePercentage”: -10.414756619131635  
},  
“bonusesLastMonth”: {  
“amount”: 28347387.119998183,  
“currencyCode”: “USD”,  
“changePercentage”: 4.433203161986422  
},  
“incomeLastMonth”: {  
“amount”: 43152444.72000217,  
“currencyCode”: “USD”,  
“changePercentage”: 4.433203161986422  
}}},  
 ![image](https://us1.discourse-cdn.com/getpostman/original/3X/1/0/106d3c24fd086a57ed0c2132aa2f927b067d16e6.png)
3. Verify the response:  
pm.test(“data verificationn”, function () {  
let jsonData = pm.response.json();  
pm.expect(jsonData.earnings.commissionLastWeek.amount).to.eql(Number(data.earningscommissionLastWeekamount));  
});  
 ![image](https://us1.discourse-cdn.com/getpostman/original/3X/3/1/318415aa58835785944889f1520159170ea7684a.png)

Error: AssertionError: object tested must be an array, a map, an object, a set, a string, or a weakset, but number given

P.S.

1. I tried to get type of particular attribute through console logs and its say “number” but sill error exist.

2. I give “include” in script since .csv file not save value as “13490064.0000046”, Its always save as “13490064”.  
 ![image](https://us1.discourse-cdn.com/getpostman/original/3X/c/9/c9256c752297136fd9233f647f3f2f115161fd73.png)  
We can give “eql or equal” if value is in integer.

So how we can resolve issue with “include”?  
How we can save .csv file with full value “13490064.0000046”?

Let me know still needed more details.

---

<div class="post-metadata">

**Author:** ![vdespa](https://sea2.discourse-cdn.com/getpostman/user_avatar/community.postman.com/vdespa/32/2770_2.png) [@vdespa](https://community.postman.com/u/vdespa)\
**Post date:** [October 20, 2020, 6:43pm UTC](https://community.postman.com/t/assertionerror-object-tested-must-be-an-array-a-map-an-object-a-set-a-string-or-a-weakset-but-number-given/16924/2 "2020-10-20T18:43:43Z")

</div>

I would try to better isolate the source of the error you are getting. It seems to me that the error is originating in the first expectation. (the one with .to.include), not in the second one, as you seem to think.

It looks like projectedPremierVolumeThisMonth is not an array or similar.

---

<div class="post-metadata">

**Author:** ![prabhumohan09](https://sea2.discourse-cdn.com/getpostman/user_avatar/community.postman.com/prabhumohan09/32/5961_2.png) [@prabhumohan09](https://community.postman.com/u/prabhumohan09)\
**Post date:** [October 20, 2020, 6:55pm UTC](https://community.postman.com/t/assertionerror-object-tested-must-be-an-array-a-map-an-object-a-set-a-string-or-a-weakset-but-number-given/16924/3 "2020-10-20T18:55:58Z")

</div>

Hi @aakashjain8693,

Could you drill down the assertion block one by one and get identify which response data gives the actual problem. If you want to validate the first part of the value as you described in your verification part. Try to store in a variable and split using dot operator then you can assert with your expected value. thanks

---

<div class="post-metadata">

**Author:** ![aakashjain8693](https://avatars.discourse-cdn.com/v4/letter/a/7c8e57/32.png) [@aakashjain8693](https://community.postman.com/u/aakashjain8693)\
**Post date:** [October 21, 2020, 5:31am UTC](https://community.postman.com/t/assertionerror-object-tested-must-be-an-array-a-map-an-object-a-set-a-string-or-a-weakset-but-number-given/16924/4 "2020-10-21T05:31:42Z")

</div>

@vdespa No I was following the second linde of code only not the first one.  
You can see the reference here.

 ![image](https://us1.discourse-cdn.com/getpostman/original/3X/b/a/bae41bbc132f24cc17b596264bf1802022b5b299.png)

You can see the console, required path have exact the same number.

 ![image](https://us1.discourse-cdn.com/getpostman/original/3X/0/0/00455401e2f73dc87da507038dbb95da3e41b887.png)

Looks like my script too perfect cause when I add equal only, Verification failed as below with incorrect number. It mean path is same.

 ![image](https://us1.discourse-cdn.com/getpostman/original/3X/c/f/cf15a8a49936fb964139c37d0e2019024855c690.png)  
 ![image](https://us1.discourse-cdn.com/getpostman/original/3X/2/9/291b6166cb0da48f3d338099a2f7e93402233821.png)

@prabhumohan09 Hope clear with some sets of cases.

@vdespa @allenheltondev Any suggestion?  
How I can verify in other ways?  
How I can write value with decimal operator permanently in .csv file without format always?

---

<div class="post-metadata">

**Author:** ![aakashjain8693](https://avatars.discourse-cdn.com/v4/letter/a/7c8e57/32.png) [@aakashjain8693](https://community.postman.com/u/aakashjain8693)\
**Post date:** [October 21, 2020, 9:00am UTC](https://community.postman.com/t/assertionerror-object-tested-must-be-an-array-a-map-an-object-a-set-a-string-or-a-weakset-but-number-given/16924/5 "2020-10-21T09:00:28Z")

</div>

@vdespa @prabhumohan09 I tried with Match assertion and working fine with hard code expected value:

 ![image](https://us1.discourse-cdn.com/getpostman/original/3X/0/2/027b95f2639232464465bd248bd15ff7f0f20c18.png)

But when trying to verify data through .csv file, error occured. Tried with “”, (), {} but still no luck.

 ![image](https://us1.discourse-cdn.com/getpostman/original/3X/b/b/bb527eeb30d62b27a882731105c7264cce9724a9.png)  
AssertionError: expected 13490064.0000046 to match /data.earningscommissionLastWeekamount/

---

<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:43pm UTC](https://community.postman.com/t/assertionerror-object-tested-must-be-an-array-a-map-an-object-a-set-a-string-or-a-weakset-but-number-given/16924/6 "2020-10-21T13:43:33Z")

</div>

You could try casting these values as strings instead of numbers since you’re obviously losing precision casting it as a number.

---

<div class="post-metadata">

**Author:** ![aakashjain8693](https://avatars.discourse-cdn.com/v4/letter/a/7c8e57/32.png) [@aakashjain8693](https://community.postman.com/u/aakashjain8693)\
**Post date:** [October 21, 2020, 5:19pm UTC](https://community.postman.com/t/assertionerror-object-tested-must-be-an-array-a-map-an-object-a-set-a-string-or-a-weakset-but-number-given/16924/7 "2020-10-21T17:19:25Z")

</div>

Tried string casting too but no luck!!

 ![image](https://us1.discourse-cdn.com/getpostman/original/3X/d/9/d9b1a8200dcd659d426128e8689c88af42541540.png)

---

<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, 5:33pm UTC](https://community.postman.com/t/assertionerror-object-tested-must-be-an-array-a-map-an-object-a-set-a-string-or-a-weakset-but-number-given/16924/8 "2020-10-21T17:33:25Z")

</div>

Can you try adding console logs to both things you are asserting so we can see what the values are?

```auto
console.log(jsonData.earnings.commissionLastWeek.amount);
console.log(data.earningscommissionLastWeekamount);

```

---

<div class="post-metadata">

**Author:** ![aakashjain8693](https://avatars.discourse-cdn.com/v4/letter/a/7c8e57/32.png) [@aakashjain8693](https://community.postman.com/u/aakashjain8693)\
**Post date:** [October 21, 2020, 6:03pm UTC](https://community.postman.com/t/assertionerror-object-tested-must-be-an-array-a-map-an-object-a-set-a-string-or-a-weakset-but-number-given/16924/9 "2020-10-21T18:03:27Z")

</div>

both have the same values:

 ![image](https://us1.discourse-cdn.com/getpostman/original/3X/4/6/46866fa3d4762ffd2b875dd16036fbbf54b40d10.png)

---

<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, 6:18pm UTC](https://community.postman.com/t/assertionerror-object-tested-must-be-an-array-a-map-an-object-a-set-a-string-or-a-weakset-but-number-given/16924/10 "2020-10-21T18:18:15Z")

</div>

Is that after casting either value?

Obviously those aren’t the exact same, so I’d expect the assertion to fail. Just not for the reason you’re seeing.

---

<div class="post-metadata">

**Author:** ![aakashjain8693](https://avatars.discourse-cdn.com/v4/letter/a/7c8e57/32.png) [@aakashjain8693](https://community.postman.com/u/aakashjain8693)\
**Post date:** [October 21, 2020, 6:33pm UTC](https://community.postman.com/t/assertionerror-object-tested-must-be-an-array-a-map-an-object-a-set-a-string-or-a-weakset-but-number-given/16924/11 "2020-10-21T18:33:30Z")

</div>

I already tried with casting and and it got failed as above error message.  
Yes, those are not exact same due to some restriction from .csv file hence we are using include/match chai assertion for verification.

Anyway I already gave casting script for them as above, Do you have any other solution.

---

<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 22, 2020, 11:41am UTC](https://community.postman.com/t/assertionerror-object-tested-must-be-an-array-a-map-an-object-a-set-a-string-or-a-weakset-but-number-given/16924/12 "2020-10-22T11:41:38Z")

</div>

What is this data object you’re trying to assert on? If you’re just pulling out of a csv, I probably would have just done it this way:

```auto
const commissionLastWeek = pm.iterationData.get('earningscommissionLastWeekamount');
pm.expect(jsonData.earnings.commissionLastWeek.amount).to.equal(commissionLastWeek);

```

The only thing I can think of is that something is wrong with however you’re creating that `data` object.

---

<div class="post-metadata">

**Author:** ![aakashjain8693](https://avatars.discourse-cdn.com/v4/letter/a/7c8e57/32.png) [@aakashjain8693](https://community.postman.com/u/aakashjain8693)\
**Post date:** [October 22, 2020, 7:09pm UTC](https://community.postman.com/t/assertionerror-object-tested-must-be-an-array-a-map-an-object-a-set-a-string-or-a-weakset-but-number-given/16924/13 "2020-10-22T19:09:53Z")

</div>

const commissionLastWeek = pm.iterationData.get(‘earningscommissionLastWeekamount’);  
pm.expect(jsonData.earnings.commissionLastWeek.amount).to.include(Number(commissionLastWeek));

Same an issue. @allenheltondev You might be missing something but let me give something important in nutshell. Lets connect over screen share if possible, If required.

1. Response contain value for earnings.commissionLastWeek.amount as “13490064.0000046”  
where as In .csv file I am putting same value as “13490064.0000046” but unfortunately file save value only integer value(13490064), It will not include decimal part.  
To overcome, In assertion we give “include” but its throw error  
pm.expect(jsonData.earnings.commissionLastWeek.amount).to.include(commissionLastWeek);  

2. Where as If we give equal/eql assertion type, Throw the correct error as  
pm.expect(jsonData.earnings.commissionLastWeek.amount).to.equal(commissionLastWeek);

---

<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 23, 2020, 11:21am UTC](https://community.postman.com/t/assertionerror-object-tested-must-be-an-array-a-map-an-object-a-set-a-string-or-a-weakset-but-number-given/16924/14 "2020-10-23T11:21:08Z")

</div>

Oh, I see your problem, thank you for clarifying.

`.includes` doesn’t apply to numbers.

Instead, you could use `Math.trunc` if you really don’t care about the precision.

```auto
pm.expect(Math.trunc(jsonData.earnings.commissionLastWeek.amount)).to.equal(Math.trunc(commissionLastWeek));

```

---

<div class="post-metadata">

**Author:** ![aakashjain8693](https://avatars.discourse-cdn.com/v4/letter/a/7c8e57/32.png) [@aakashjain8693](https://community.postman.com/u/aakashjain8693)\
**Post date:** [October 24, 2020, 9:31am UTC](https://community.postman.com/t/assertionerror-object-tested-must-be-an-array-a-map-an-object-a-set-a-string-or-a-weakset-but-number-given/16924/15 "2020-10-24T09:31:16Z")

</div>

Thanks @allenheltondev, Here is the my type of script and working fine without issues. pm.expect(Math.trunc(jsonData.earnings.commissionLastWeek.amount)).to.eql(data.earningscommissionLastWeekamount);

I will mark as solution but just for leaning and out of the postman related question who I can make .csv file data(100.45) with precision?

Issues with .csv file: In .csv file I am putting value as “13490064.0000046” but unfortunately file save value only integer value(13490064), It will not include decimal part.  
Thought we can format it but once you close the file, values will reset and again no precision there.  
Any suggestions?

---

<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 26, 2020, 11:20am UTC](https://community.postman.com/t/assertionerror-object-tested-must-be-an-array-a-map-an-object-a-set-a-string-or-a-weakset-but-number-given/16924/16 "2020-10-26T11:20:17Z")

</div>

It might have something to do with the program you’re using to manipulate the csv (like excel). But you could certainly try to surround the number in quotes to preserve the number as text, then you wouldn’t get any data loss.

---

<div class="post-metadata">

**Author:** ![odanylewycz](https://sea2.discourse-cdn.com/getpostman/user_avatar/community.postman.com/odanylewycz/32/3240_2.png) [@odanylewycz](https://community.postman.com/u/odanylewycz)\
**Post date:** [October 26, 2020, 12:04pm UTC](https://community.postman.com/t/assertionerror-object-tested-must-be-an-array-a-map-an-object-a-set-a-string-or-a-weakset-but-number-given/16924/17 "2020-10-26T12:04:03Z")

</div>

Hi @aakashjain8693,

As @allenheltondev noted, this is likely due to the client you are using to view the csv data. CSV file type is somewhat primitive (although very useful), meaning there is no context behind the data inferred. The clients used infer that, and likely in this case, Excel infers it to be an integer.

Best bet it so use quotes and they should be inferred as strings, leaving you with the precision you are looking for. This should work but again its dependent on the client being used to consume the csv. Though if you’re looking to do any numeric manipulations on code, you will have to cast it to the appropriate type (float, double, etc).

---

<div class="post-metadata">

**Author:** ![aakashjain8693](https://avatars.discourse-cdn.com/v4/letter/a/7c8e57/32.png) [@aakashjain8693](https://community.postman.com/u/aakashjain8693)\
**Post date:** [October 27, 2020, 11:26am UTC](https://community.postman.com/t/assertionerror-object-tested-must-be-an-array-a-map-an-object-a-set-a-string-or-a-weakset-but-number-given/16924/18 "2020-10-27T11:26:44Z")

</div>

Perfect, Thanks!!  
It might be the client type since unable to preserve the number as text through quotes.

Thanks @allenheltondev @odanylewycz

---

<div class="post-metadata">

**Author:** ![expressdoc](https://avatars.discourse-cdn.com/v4/letter/e/a6a055/32.png) [@expressdoc](https://community.postman.com/u/expressdoc)\
**Post date:** [January 7, 2022, 4:33am UTC](https://community.postman.com/t/assertionerror-object-tested-must-be-an-array-a-map-an-object-a-set-a-string-or-a-weakset-but-number-given/16924/19 "2022-01-07T04:33:11Z")

</div>

![Screenshot (256)](https://us1.discourse-cdn.com/getpostman/original/3X/4/c/4c7fc42ab18422fc0b6959c9ccf6d5d0a648dea1.png)

Hi guys can anyone tell me how to pass an array into get request url…
