Use this file to discover all available pages before exploring further.
Type and existence matchers let you assert what kind of value you are dealing with before making deeper assertions. They are especially important in ExtendScript environments where Adobe host APIs can return null, undefined, or custom object types in ways that differ from standard JavaScript. All of the matchers documented here return this, so they are fully chainable.
Asserts that the actual value is a numberand is not NaN. This intentionally excludes NaN because NaN is not a valid numeric value for most arithmetic purposes.
// ✅ Passesexpect(42).toBeNumber();expect(0).toBeNumber();expect(-5.5).toBeNumber();// ❌ Throws — NaN is excludedexpect(() => expect(NaN).toBeNumber()).toThrow();// ❌ Throws — string '42' is not a number typeexpect(() => expect('42').toBeNumber()).toThrow();expect(() => expect(null).toBeNumber()).toThrow();
NaN has the JavaScript type "number" but toBeNumber() explicitly rejects it. Use toBeNaN() to assert that a value is NaN.
Asserts that the actual value is NaN. This is useful when testing the output of operations that produce NaN on invalid input, such as parseInt on a non-numeric string.
// ✅ Passesexpect(NaN).toBeNaN();expect(parseInt('invalid')).toBeNaN();// ❌ Throws — 42 is a valid number, not NaNexpect(() => expect(42).toBeNaN()).toThrow();
Asserts that the actual value is an Array by checking value.constructor === Array. This approach works correctly in ExtendScript, where instanceof behaviour can differ across execution contexts.
// ✅ Passesexpect([]).toBeArray();expect([1, 2, 3]).toBeArray();// ❌ Throws — plain objects are not arraysexpect(() => expect({}).toBeArray()).toThrow();expect(() => expect('abc').toBeArray()).toThrow();
Truthiness matchers check whether a value is truthy or falsy according to JavaScript’s standard coercion rules, or whether a value is strictly the boolean literal true or false.
Asserts that the actual value is truthy — any value for which !!value === true. This includes non-zero numbers, non-empty strings, objects, arrays (even empty ones), and true itself.
Asserts that the actual value is falsy — any value for which !value === true. The falsy values in JavaScript are false, 0, "", null, undefined, and NaN.
Asserts that the actual value is an instance of the given constructor. The check first compares value.constructor === expected, then falls back to value instanceof expected. This two-step approach ensures correct behaviour with both standard JavaScript classes and Adobe host application classes (such as CompItem, Layer, File, etc.) where instanceof may not behave as expected across execution contexts.
class TestClass {}const instance = new TestClass();// ✅ Passesexpect(instance).toBeInstanceOf(TestClass);
// ✅ Also works with Adobe built-in classes inside a host applicationconst comp = app.project.items.addComp('Test', 1920, 1080, 1, 10, 30);expect(comp).toBeInstanceOf(CompItem);comp.remove();
// ❌ Throws — plain object is not a TestClass instanceexpect(() => expect({}).toBeInstanceOf(TestClass)).toThrow();// ❌ Throws — null is not an instance of anythingexpect(() => expect(null).toBeInstanceOf(TestClass)).toThrow();
null and undefined are handled explicitly: passing either as the actual value always fails with a descriptive message naming the expected constructor, even before instanceof is evaluated.
When testing Adobe host objects such as CompItem, AVLayer, ShapeLayer, or File, prefer toBeInstanceOf over toBeFile/toBeFolder for custom Adobe types. The IO matchers (toBeFile, toBeFolder) specifically target ExtendScript’s built-in File and Folder classes.
Asserts that the actual value is a function and that it throws an error when called. The matcher calls the function with no arguments and catches any exception. If the function does not throw, or if the actual value is not a function at all, the assertion fails.
// ✅ Passes — function throwsexpect(() => { throw new Error('Test error');}).toThrow();// ✅ Passes — function with a failing inner assertion also throwsexpect(() => { expect(5).toBeString();}).toThrow();// ❌ Throws — function does not throwexpect(() => expect(() => 42).toThrow()).toThrow();
toThrow only works on functions. Passing a non-function value (such as 42, null, or undefined) always fails the assertion — the matcher cannot execute a non-function, so it cannot determine whether it would throw.
// ❌ All fail — non-function values cannot be tested with toThrowexpect(() => expect(42).toThrow()).toThrow();expect(() => expect(null).toThrow()).toThrow();expect(() => expect(undefined).toThrow()).toThrow();
Use not().toThrow() to assert that a function completes without throwing. See the Negation page for detailed examples.Signature: