Skip to content

Assertions Reference

open Scriptorium.Nib.Assertion
AssertionPasses when
isEqualTo expectedsubject equals expected (structural equality, shows diff on failure)
isNotEqualTo expectedsubject does not equal expected
isGreaterThan thresholdsubject > threshold
isGreaterOrEqual thresholdsubject ≥ threshold
isLessThan thresholdsubject < threshold
isLessOrEqual thresholdsubject ≤ threshold
satisfy predicatepredicate returns true
assertThat 42 (isEqualTo 42)
assertThat 42 (isGreaterThan 0 >> isLessThan 100)
assertThat 18 (isGreaterOrEqual 18) // boundary — passes
assertThat "hi" (satisfy (fun s -> s.Length > 0))
AssertionPasses when
isTruetrue
isFalsefalse
isNotTruefalse
isNotFalsetrue
AssertionPasses when
isNullsubject is null
isNotNullsubject is not null
AssertionPasses when
throwsthunk throws; shifts subject to the caught exception
throwsWithMessage msgthunk throws with exactly msg; shifts subject to exception
doesNotThrowthunk completes without throwing
assertThat (fun () -> failwith "boom") (throwsWithMessage "boom")
// Continue asserting on the exception itself
assertThat (fun () -> failwith "boom") (
throws
>> focus _.Message
>> isEqualTo "boom"
)
assertThat (fun () -> ignore (1 + 1)) doesNotThrow
AssertionPasses when
hasSize nlist has exactly n elements
isEmptylist is empty
isNotEmptylist has at least one element
contain xlist contains x
notContain xlist does not contain x
startWith prefixlist begins with prefix (shows diff on failure)
haveSameSizeAs othersame length as other
beSameAs expectedsame elements in same order (shows diff)
haveSameElements expectedsame elements in any order (sorts both before comparing)
assertThat [1; 2; 3] (
isNotEmpty
>> hasSize 3
>> contain 2
>> startWith [1]
>> haveSameElements [3; 1; 2]
)

Use inside to drill into elements:

assertThat [{ Name = "alice"; Age = 25 }] (
hasSize 1
>> inside List.head (
inside _.Name (tag "name" >> isNotEqualTo "")
>> inside _.Age (tag "age" >> isGreaterOrEqual 18)
)
)
AssertionPasses when
Option.isSomeoption is Some
Option.isNoneoption is None
Option.valueoption is Some; shifts subject to the inner value (aborts if None)
assertThat (Some 42) (Option.value >> isEqualTo 42)
assertThat (None : int option) Option.isNone
AssertionPasses when
Result.isOkresult is Ok
Result.isErrorresult is Error
Result.okValueresult is Ok; shifts subject to the inner value (aborts if Error)
Result.errorValueresult is Error; shifts subject to the error (aborts if Ok)
assertThat (Ok 42 : Result<int, string>) (Result.okValue >> isEqualTo 42)
assertThat (Error "oops" : Result<int, string>) (Result.errorValue >> isEqualTo "oops")