Postman uses the Chai assertion library under the hood. When you write pm.expect(value).to.eql(42) — that's Chai syntax. Understanding Chai gives you 50+ assertion methods to validate anything. Think of it as your testing vocabulary. The more words you know, the better you can express what you're checking.
Bookmark this table. You'll come back to it every day until it becomes muscle memory.
| Assertion | What It Checks | Example |
|---|---|---|
| to.eql(value) | Deep equality (objects/arrays) | pm.expect({a:1}).to.eql({a:1}) |
| to.equal(value) | Strict equality (===) | pm.expect(42).to.equal(42) |
| to.be.a(type) | Type check | pm.expect("hi").to.be.a("string") |
| to.be.an(type) | Type check (for "array", "object") | pm.expect([]).to.be.an("array") |
| to.include(value) | String contains / array includes | pm.expect("hello").to.include("hell") |
| to.have.property(key) | Object has a key | pm.expect(obj).to.have.property("id") |
| to.have.all.keys(...) | Object has ALL listed keys | pm.expect(obj).to.have.all.keys("id","name") |
| to.have.lengthOf(n) | String/array length | pm.expect([1,2,3]).to.have.lengthOf(3) |
| to.be.true / .false | Boolean check | pm.expect(true).to.be.true |
| to.be.null | Null check | pm.expect(null).to.be.null |
| to.be.undefined | Undefined check | pm.expect(undefined).to.be.undefined |
| to.be.empty | Empty string, array, or object | pm.expect([]).to.be.empty |
| to.be.above(n) | Greater than | pm.expect(10).to.be.above(5) |
| to.be.below(n) | Less than | pm.expect(3).to.be.below(10) |
| to.be.within(a, b) | Range check (inclusive) | pm.expect(5).to.be.within(1, 10) |
| to.be.oneOf([...]) | Value is in the list | pm.expect("a").to.be.oneOf(["a","b"]) |
| to.match(regex) | Matches a regex | pm.expect("abc123").to.match(/[a-z]+\d+/) |
| to.not.eql(value) | Negation — NOT equal | pm.expect(1).to.not.eql(2) |
// eql() vs equal() — know the difference
// Numbers and strings — both work
pm.expect(42).to.equal(42); // PASS
pm.expect(42).to.eql(42); // PASS
// Objects — only eql() works
const a = { name: "John" };
const b = { name: "John" };
pm.expect(a).to.eql(b); // PASS (same values)
pm.expect(a).to.equal(b); // FAIL (different references!)
// Rule: use eql() for everything. It's safer.// You can chain multiple checks in one assertion
pm.test("Title is a non-empty string", function () {
const response = pm.response.json();
pm.expect(response.title)
.to.be.a("string")
.and.not.be.empty
.and.have.lengthOf.above(5);
});
// Negation — use .not anywhere in the chain
pm.test("Error field does not exist", function () {
const response = pm.response.json();
pm.expect(response).to.not.have.property("error");
});Key Point: Use eql() for comparing values (especially objects/arrays). Use equal() only for primitives. When in doubt, use eql() — it always works.
Print the Chai cheat sheet and stick it next to your monitor. After 2 weeks, you won't need it. But for those first 2 weeks, it saves 50% of your Googling.
Q: What assertion library does Postman use? Explain eql() vs equal().
A: Postman uses the Chai assertion library with the BDD (expect) syntax. eql() does deep equality — it compares values recursively, so two different objects with the same properties will pass. equal() does strict equality (===) — it compares references, so two objects with the same values will fail because they're different instances in memory. For API testing, I almost always use eql() because I'm comparing response values, not references.
Key Point: Chai gives you 50+ assertion methods. Master eql, be.a, include, have.property, have.lengthOf, be.above, be.below, be.oneOf, and match — these cover 95% of API test cases.