Skip to content

Range & Array Operations

Test collections with these assertions.

contain

Asserts that an array or range contains the expected element.

expect([1, 2, 3]).to.contain(2);
expect(["a", "b", "c"]).to.contain("b");

containOnly

Asserts that an array contains only the specified elements (in any order).

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

beEmpty

Asserts that an array or range is empty.

int[] empty;
expect(empty).to.beEmpty();
expect([]).to.beEmpty();

beSorted

Asserts that an array is sorted in ascending order.

expect([1, 2, 3, 4, 5]).to.beSorted();