KT Testing Suite Core provides two fundamental equality matchers:Documentation Index
Fetch the complete documentation index at: https://mintlify.com/Octopodo/kt-testing-suite-core/llms.txt
Use this file to discover all available pages before exploring further.
toBe for checking that two values are the exact same reference or primitive, and toEqual for comparing the serialised structure of objects and arrays. Understanding the difference between them is essential — choosing the wrong one is one of the most common sources of unexpected test failures.
toBe(expected)
toBe asserts that the actual value is strictly identical to the expected value using the === operator. For primitives (number, string, boolean, null, undefined) this means same type and same value. For objects and arrays it means the same reference in memory — two separate objects with identical properties will not pass.
| Parameter | Type | Description |
|---|---|---|
expected | any | The value to compare against using ===. |
toEqual(expected)
toEqual asserts deep structural equality by serialising both values with JSON.stringify and comparing the resulting strings. This makes it ideal for comparing plain objects, nested objects, and arrays by content rather than reference.
Because
toEqual relies on JSON.stringify, values that are not JSON-serialisable — such as functions, undefined object properties, or circular references — may produce unexpected results. For those cases, assert individual properties with toHaveProperty instead.| Parameter | Type | Description |
|---|---|---|
expected | object | The value to compare against using deep JSON equality. |
When to use toBe vs toEqual
| Use case | Recommended matcher |
|---|---|
| Comparing numbers, strings, booleans | toBe |
Checking null or undefined | toBe |
| Comparing the same object reference | toBe |
| Comparing two objects by their contents | toEqual |
| Comparing two arrays by their elements | toEqual |
| Comparing nested objects | toEqual |
Edge cases: null and undefined
null and undefined are distinct values in ExtendScript. toBe correctly distinguishes them because null === undefined is false. toEqual also distinguishes them because JSON.stringify(null) returns "null" while JSON.stringify(undefined) returns undefined (which does not equal "null").
Full examples from the test suite
The following examples are taken directly frombaseMatchers.test.ts and show the happy path, grey path, and sad path for both matchers: