# Assertion Error when using an integer data type

**URL:** <https://community.postman.com/t/assertion-error-when-using-an-integer-data-type/50265>\
**Category:** Help Hub\
**Tags:** tests, chai\
**Created:** [August 4, 2023, 7:57am UTC](https://community.postman.com/t/assertion-error-when-using-an-integer-data-type/50265 "2023-08-04T07:57:37Z")\
**Posts on this page:** 12\
**Page:** 1

<div class="post-metadata">

**Author:** ![vladimir.camaj](https://avatars.discourse-cdn.com/v4/letter/v/a698b9/32.png) [@vladimir.camaj](https://community.postman.com/u/vladimir.camaj)\
**Post date:** [August 4, 2023, 7:57am UTC](https://community.postman.com/t/assertion-error-when-using-an-integer-data-type/50265/1 "2023-08-04T07:57:37Z")

</div>

Hi I have a test which should test if returned id exists and if its integer. But I am getting this error which does not make sense to me.  
**AssertionError: expected 104 to be an integer**

```auto
var id = data.id ? data.id : null;

pm.test('Required id test', function() {
      pm.expect(id).to.be.an('integer');
});

```

What is wrong with it?

---

<div class="post-metadata">

**Author:** ![danny-dainton](https://sea2.discourse-cdn.com/getpostman/user_avatar/community.postman.com/danny-dainton/32/29401_2.png) [@danny-dainton](https://community.postman.com/u/danny-dainton)\
**Post date:** [August 4, 2023, 9:15am UTC](https://community.postman.com/t/assertion-error-when-using-an-integer-data-type/50265/2 "2023-08-04T09:15:24Z")

</div>

Hey @vladimir.camaj

I believe the syntax for that data type is `.to.be.a('number')`. Does that work if you change it to that?

---

<div class="post-metadata">

**Author:** ![michaelderekjones](https://sea2.discourse-cdn.com/getpostman/user_avatar/community.postman.com/michaelderekjones/32/14819_2.png) [@michaelderekjones](https://community.postman.com/u/michaelderekjones)\
**Post date:** [August 4, 2023, 9:31am UTC](https://community.postman.com/t/assertion-error-when-using-an-integer-data-type/50265/3 "2023-08-04T09:31:48Z")

</div>

Here is another way of doing it.

```auto
var id = 123

pm.test('Required id test', function() {
    pm.expect(Number.isInteger(id)).to.be.true
});

```

---

<div class="post-metadata">

**Author:** ![vladimir.camaj](https://avatars.discourse-cdn.com/v4/letter/v/a698b9/32.png) [@vladimir.camaj](https://community.postman.com/u/vladimir.camaj)\
**Post date:** [August 4, 2023, 10:59am UTC](https://community.postman.com/t/assertion-error-when-using-an-integer-data-type/50265/4 "2023-08-04T10:59:26Z")

</div>

This works, but can you explain me please why integer does not work but number works? It does not make any sense. Also number can be also a float…

---

<div class="post-metadata">

**Author:** ![vladimir.camaj](https://avatars.discourse-cdn.com/v4/letter/v/a698b9/32.png) [@vladimir.camaj](https://community.postman.com/u/vladimir.camaj)\
**Post date:** [August 4, 2023, 10:59am UTC](https://community.postman.com/t/assertion-error-when-using-an-integer-data-type/50265/5 "2023-08-04T10:59:55Z")

</div>

This works too but why integer test does not work?

---

<div class="post-metadata">

**Author:** ![danny-dainton](https://sea2.discourse-cdn.com/getpostman/user_avatar/community.postman.com/danny-dainton/32/29401_2.png) [@danny-dainton](https://community.postman.com/u/danny-dainton)\
**Post date:** [August 4, 2023, 11:06am UTC](https://community.postman.com/t/assertion-error-when-using-an-integer-data-type/50265/6 "2023-08-04T11:06:03Z")

</div>

All of that magic and functionality within the `pm.expect()` function comes directly from the [Chai Js](https://www.chaijs.com/api/bdd) library.

Having a `number` keyword is how the creators/maintainers of that library have implemented that functionality. I wouldn’t really be able to provide any reasoning behind that decision. 😓

---

<div class="post-metadata">

**Author:** ![michaelderekjones](https://sea2.discourse-cdn.com/getpostman/user_avatar/community.postman.com/michaelderekjones/32/14819_2.png) [@michaelderekjones](https://community.postman.com/u/michaelderekjones)\
**Post date:** [August 4, 2023, 11:11am UTC](https://community.postman.com/t/assertion-error-when-using-an-integer-data-type/50265/7 "2023-08-04T11:11:37Z")

</div>

Postman is using the CHAI JS assertion library.

[Expect / Should - Chai (chaijs.com)](https://www.chaijs.com/api/bdd/)

Integer is not a valid string type that can be used with “to.be.a”.

CHAI actually uses type detect for this aspect.

[GitHub - chaijs/type-detect: Improved typeof detection for node.js and the browser.](https://github.com/chaijs/type-detect)

When hit with issues like this, Postman is using JavaScript under the hood so searching the web including “JavaScript” in the search terms will usually give you a few hits and point you in the right direction.

Number.isInteger() is the recommended way of checking if a number is an integer.

---

<div class="post-metadata">

**Author:** ![danny-dainton](https://sea2.discourse-cdn.com/getpostman/user_avatar/community.postman.com/danny-dainton/32/29401_2.png) [@danny-dainton](https://community.postman.com/u/danny-dainton)\
**Post date:** [August 4, 2023, 11:54am UTC](https://community.postman.com/t/assertion-error-when-using-an-integer-data-type/50265/8 "2023-08-04T11:54:20Z")

</div>

Randomly, I was just notified of an upvote on this post from a couple of years ago 😂

> <https://stackoverflow.com/questions/64749910/why-can-i-only-check-for-number-in-postman-tests-but-for-integer-when-testi/64750285#64750285>

---

<div class="post-metadata">

**Author:** ![michaelderekjones](https://sea2.discourse-cdn.com/getpostman/user_avatar/community.postman.com/michaelderekjones/32/14819_2.png) [@michaelderekjones](https://community.postman.com/u/michaelderekjones)\
**Post date:** [August 4, 2023, 12:12pm UTC](https://community.postman.com/t/assertion-error-when-using-an-integer-data-type/50265/9 "2023-08-04T12:12:55Z")

</div>

I like the custom message that you included in that article. I’ll have to remember that exists so you don’t just get a bland “expected false to be true” message.

---

<div class="post-metadata">

**Author:** ![vladimir.camaj](https://avatars.discourse-cdn.com/v4/letter/v/a698b9/32.png) [@vladimir.camaj](https://community.postman.com/u/vladimir.camaj)\
**Post date:** [August 7, 2023, 8:10am UTC](https://community.postman.com/t/assertion-error-when-using-an-integer-data-type/50265/10 "2023-08-07T08:10:57Z")

</div>

That upvote is from me 🙂

---

<div class="post-metadata">

**Author:** ![danny-dainton](https://sea2.discourse-cdn.com/getpostman/user_avatar/community.postman.com/danny-dainton/32/29401_2.png) [@danny-dainton](https://community.postman.com/u/danny-dainton)\
**Post date:** [August 7, 2023, 8:13am UTC](https://community.postman.com/t/assertion-error-when-using-an-integer-data-type/50265/11 "2023-08-07T08:13:56Z")

</div>

Thank you, Sir.

![](https://media.tenor.com/ySWrwo9F6bEAAAAM/sherlock-benedict-cumberbatch.gif)

---

<div class="post-metadata">

**Author:** ![system](https://sea2.discourse-cdn.com/getpostman/user_avatar/community.postman.com/system/32/29796_2.png) [@system](https://community.postman.com/u/system)\
**Post date:** [November 5, 2023, 8:14am UTC](https://community.postman.com/t/assertion-error-when-using-an-integer-data-type/50265/12 "2023-11-05T08:14:49Z")

</div>

This topic was automatically closed 90 days after the last reply. New replies are no longer allowed.
