Skip to content

API Reference

This is the complete API reference for fluent-asserts. All assertions follow the BDD-style pattern:

expect(actualValue).to.operation(expectedValue);

Quick Reference

CategoryOperations
Equalityequal, approximately
ComparisongreaterThan, lessThan, between, within
Stringscontain, startWith, endWith
Ranges & Arrayscontain, containOnly, beEmpty, beSorted
CallablesthrowException, haveExecutionTime, allocateGCMemory
TypesbeNull, instanceOf

The expect Function

All assertions begin with expect:

import fluent.asserts;
// With a value
expect(42).to.equal(42);
// With a callable (for exception/memory testing)
expect({
riskyOperation();
}).to.throwException!RuntimeException;

Language Chains

These improve readability but don’t affect the assertion:

  • .to / .be / .been / .is / .that / .which
  • .has / .have / .with / .at / .of / .same
// All equivalent:
expect(value).equal(42);
expect(value).to.equal(42);
expect(value).to.be.equal(42);

Negation

Use .not to negate any assertion:

expect(42).to.not.equal(0);
expect("hello").to.not.beEmpty();

Categories

Equality

Test for value equality.

expect("hello").to.equal("hello");
expect(3.14).to.be.approximately(3.1, 0.1);

View all Equality operations

Comparison

Compare numeric values.

expect(42).to.be.greaterThan(10);
expect(42).to.be.lessThan(100);
expect(42).to.be.between(10, 100);

View all Comparison operations

Strings

Test string content.

expect("hello world").to.contain("world");
expect("hello").to.startWith("hel");
expect("hello").to.endWith("llo");

View all String operations

Ranges & Arrays

Test collections.

expect([1, 2, 3]).to.contain(2);
expect([1, 2, 3]).to.containOnly([1, 2, 3]);
expect([]).to.beEmpty();
expect([1, 2, 3]).to.beSorted();

View all Range operations

Callables & Exceptions

Test function behavior.

expect({
throw new Exception("error");
}).to.throwException!Exception;
expect({
safeOperation();
}).to.not.throwAnyException();
expect({
auto arr = new int[1000];
}).to.allocateGCMemory();

View all Callable operations

Types

Test type properties.

void delegate() action = null;
expect(action).to.beNull();
expect(myObject).to.be.instanceOf!MyClass;

View all Type operations