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
| Category | Operations |
|---|---|
| Equality | equal, approximately |
| Comparison | greaterThan, lessThan, between, within |
| Strings | contain, startWith, endWith |
| Ranges & Arrays | contain, containOnly, beEmpty, beSorted |
| Callables | throwException, haveExecutionTime, allocateGCMemory |
| Types | beNull, instanceOf |
The expect Function
All assertions begin with expect:
import fluent.asserts;
// With a valueexpect(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);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");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();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();Types
Test type properties.
void delegate() action = null;expect(action).to.beNull();
expect(myObject).to.be.instanceOf!MyClass;