Assert on arrays and strings with toBeEmpty, toHaveLength, toContain, toInclude, toHaveProperty, and toPassAny for flexible multi-condition assertions.
Use this file to discover all available pages before exploring further.
Collection matchers operate on arrays, strings, and plain objects. They let you assert on size, membership, substring presence, and object shape. Additionally, toPassAny provides a flexible mechanism for expressing OR-style conditions — the assertion passes as long as at least one condition in the provided list is satisfied.
Asserts that the actual value has a length of zero. The matcher accepts arrays, strings, null, and undefined — all of which are considered empty when their effective length is zero. Any other type that is not an array or string also fails because it has no meaningful length.
null and undefined are treated as empty by both toBeEmpty and toHaveLength. This is intentional for ExtendScript environments where Adobe APIs sometimes return null instead of an empty collection.
Asserts that the actual value has exactly the given length. Works with arrays and strings. null and undefined are treated as having a length of 0, so toHaveLength(0) passes for them.
Asserts that the actual string contains the expected substring. This is a string-only matcher — the actual value must be a string. Use toInclude for array membership.
Asserts that the actual array includes the expected element using strict equality (===) for each comparison. The actual value must be an Array — non-array values always fail.
// ✅ Passesexpect([1, 2, 3]).toInclude(2);expect(['a', 'b']).toInclude('a');// ❌ Throws — element not presentexpect(() => expect([1, 2]).toInclude(3)).toThrow();// ❌ Throws — not an arrayexpect(() => expect('abc').toInclude('a')).toThrow();
Signature:
toInclude(expected: any): this
Parameter
Type
Description
expected
any
The element to search for in the actual array using ===.
Asserts that the actual object has an own property matching the given key. When the optional value argument is provided, the matcher additionally checks that object[property] === value.
The property check uses hasOwnProperty, so inherited properties from the prototype chain do not satisfy the assertion. The value comparison (when provided) uses strict === equality.
Signature:
toHaveProperty(property: string, value?: any): this
Parameter
Type
Description
property
string
The own property key to check for.
value
any
(Optional) If provided, the property must equal this value via ===.
Asserts that the actual value satisfies at least one condition from the provided array. If every condition fails, the matcher throws a combined error listing all individual failure messages. This is useful when a value may legitimately be one of several types or states.The conditions array accepts three forms per element:
Form
Example
Description
String (no args)
'toBeString'
Calls the named matcher with no argument.
Object (with arg)
{ toBeGreaterThan: 3 }
Calls the named matcher with the given value.
'Not' suffix on string
'toBeStringNot'
Calls not() then the named matcher (strips Not from the end).
'Not' suffix on object key
{ toBeLessThanNot: 3 }
Same negation, but passes the value as the matcher argument.
// ✅ Passes — value is a number (first condition)expect(5).toPassAny(['toBeNumber', 'toBeString']);// ✅ Passes — using object form with argumentexpect(5).toPassAny([ { toBeGreaterThan: 3 }, { toBe: 99 }]);// ✅ Passes — mix of string and object conditionsexpect(5).toPassAny([ 'toBeString', { toBeGreaterThan: 10 }, { toBe: 5 }]);
Appending Not to a condition string name is equivalent to wrapping that single condition with not(). The negation applies only to that condition, not to the overall toPassAny assertion:
// ✅ Passes — 5 is NOT a string (toBeStringNot condition passes)expect(5).toPassAny([ 'toBeStringNot', { toBeLessThan: 3 }]);
Passing an empty array to toPassAny always fails with the message "No conditions provided to toPassAny".
toPassAny is used internally by toBeFileOrFolder to check whether a value is either a File or a Folder. You can use the same pattern to create your own OR-style assertions without defining a custom matcher.
Signature:
toPassAny(conditions: Array<string | Record<string, any>>): this
Parameter
Type
Description
conditions
Array<string | Record<string, any>>
One or more condition descriptors. At least one must pass.