Header menu logo testify

CheckExpectation Module

Builders and combinators for property-style expectations.

Functions and values

Function or value Description

CheckExpectation.andAlso a b

Full Usage: CheckExpectation.andAlso a b

Parameters:
    a : CheckExpectation<'Args, 'Actual, 'Expected> - The first required expectation.
    b : CheckExpectation<'Args, 'Actual, 'Expected> - The second required expectation.

Returns: CheckExpectation<'Args, 'Actual, 'Expected> A reusable expectation that succeeds only when both input expectations succeed.

Combines two expectations so that both must succeed.

a : CheckExpectation<'Args, 'Actual, 'Expected>

The first required expectation.

b : CheckExpectation<'Args, 'Actual, 'Expected>

The second required expectation.

Returns: CheckExpectation<'Args, 'Actual, 'Expected>

A reusable expectation that succeeds only when both input expectations succeed.

CheckExpectation.equalBy projection

Full Usage: CheckExpectation.equalBy projection

Parameters:
    projection : 'T -> 'Key - The projection applied to both successful values before comparison.

Returns: CheckExpectation<'Args, 'T, 'T> A reusable expectation that compares projected keys with F# equality. If either side throws, the expectation falls back to exception-shape comparison and mismatch reporting.

Builds an equality expectation after projecting both tested and reference values.

projection : 'T -> 'Key

The projection applied to both successful values before comparison.

Returns: CheckExpectation<'Args, 'T, 'T>

A reusable expectation that compares projected keys with F# equality. If either side throws, the expectation falls back to exception-shape comparison and mismatch reporting.

Example

 type Person = { Name: string; Age: int }

 Check.should(
     CheckExpectation.equalBy (fun person -> person.Age),
     (fun n -> { Name = $"ref-{n}"; Age = n }),
     <@ fun n -> { Name = $"actual-{n}"; Age = n } @>)
type Person = { Name: string Age: int }
Multiple items
val string: value: 'T -> string

--------------------
type string = System.String
Multiple items
val int: value: 'T -> int (requires member op_Explicit)

--------------------
type int = int32

--------------------
type int<'Measure> = int

CheckExpectation.equalByKey projection expectedKey

Full Usage: CheckExpectation.equalByKey projection expectedKey

Parameters:
    projection : 'T -> 'Key - The projection applied to both successful values.
    expectedKey : 'Key - The fixed projected key both the tested code and the reference must produce.

Returns: CheckExpectation<'Args, 'T, 'T> A reusable expectation for “both sides land on this key” scenarios, such as comparing records by one field or normalized representation.

Builds an equality expectation that requires both projected values to equal one fixed key.

projection : 'T -> 'Key

The projection applied to both successful values.

expectedKey : 'Key

The fixed projected key both the tested code and the reference must produce.

Returns: CheckExpectation<'Args, 'T, 'T>

A reusable expectation for “both sides land on this key” scenarios, such as comparing records by one field or normalized representation.

Example

 Check.should(
     CheckExpectation.equalByKey String.length 3,
     (fun (value: string) -> value.ToUpperInvariant()),
     <@ fun value -> value.Trim() @>)
module String from Microsoft.FSharp.Core
val length: str: string -> int
Multiple items
val string: value: 'T -> string

--------------------
type string = System.String

CheckExpectation.equalTo expected

Full Usage: CheckExpectation.equalTo expected

Parameters:
    expected : 'T - The fixed value both sides must produce.

Returns: CheckExpectation<'Args, 'T, 'T> A reusable expectation for fixed-value property checks that uses Diff.defaultOptions for mismatch rendering.

Builds an expectation that requires both tested code and the reference to equal a fixed expected value.

expected : 'T

The fixed value both sides must produce.

Returns: CheckExpectation<'Args, 'T, 'T>

A reusable expectation for fixed-value property checks that uses Diff.defaultOptions for mismatch rendering.

CheckExpectation.equalToReference

Full Usage: CheckExpectation.equalToReference

Returns: CheckExpectation<'Args, 'T, 'T> A reusable expectation that succeeds when both sides return equal successful values or throw the same exception type.

Builds an expectation that requires tested code and the reference to behave identically.

Returns: CheckExpectation<'Args, 'T, 'T>

A reusable expectation that succeeds when both sides return equal successful values or throw the same exception type.

Example

 Check.should(
     CheckExpectation.equalToReference,
     List.sort,
     <@ List.sort @>)
Multiple items
module List from Microsoft.FSharp.Collections

--------------------
type List<'T> = | op_Nil | op_ColonColon of Head: 'T * Tail: 'T list interface IReadOnlyList<'T> interface IReadOnlyCollection<'T> interface IEnumerable interface IEnumerable<'T> member GetReverseIndex: rank: int * offset: int -> int member GetSlice: startIndex: int option * endIndex: int option -> 'T list static member Cons: head: 'T * tail: 'T list -> 'T list member Head: 'T with get member IsEmpty: bool with get member Item: index: int -> 'T with get ...
val sort: list: 'T list -> 'T list (requires comparison)

CheckExpectation.equalToReferenceWithDiff diffOptions

Full Usage: CheckExpectation.equalToReferenceWithDiff diffOptions

Parameters:
    diffOptions : DiffOptions - Diff settings used when the tested code and reference return different successful values.

Returns: CheckExpectation<'Args, 'T, 'T> A reusable expectation that compares tested code and reference behavior with custom diff rendering.

Builds an equality expectation against the reference implementation using the supplied diff options.

diffOptions : DiffOptions

Diff settings used when the tested code and reference return different successful values.

Returns: CheckExpectation<'Args, 'T, 'T>

A reusable expectation that compares tested code and reference behavior with custom diff rendering.

CheckExpectation.equalToWithDiff diffOptions expected

Full Usage: CheckExpectation.equalToWithDiff diffOptions expected

Parameters:
    diffOptions : DiffOptions - Diff settings used when rendering mismatches. Use Diff.defaultOptions for the standard Testify explanation strategy, or create a custom DiffOptions value when you want different truncation or structural-diff behavior.
    expected : 'T - The fixed value both sides must produce.

Returns: CheckExpectation<'Args, 'T, 'T> A reusable expectation for fixed-value property checks with custom diff rendering.

Builds an expectation that requires both tested code and the reference to equal a fixed expected value.

diffOptions : DiffOptions

Diff settings used when rendering mismatches. Use Diff.defaultOptions for the standard Testify explanation strategy, or create a custom DiffOptions value when you want different truncation or structural-diff behavior.

expected : 'T

The fixed value both sides must produce.

Returns: CheckExpectation<'Args, 'T, 'T>

A reusable expectation for fixed-value property checks with custom diff rendering.

CheckExpectation.equalWith comparer

Full Usage: CheckExpectation.equalWith comparer

Parameters:
    comparer : 'T -> 'T -> bool - The custom equality relation. It receives the tested successful value first and the reference successful value second.

Returns: CheckExpectation<'Args, 'T, 'T> A reusable expectation that delegates successful-value comparison to comparer.

Builds an equality expectation using a custom comparer.

comparer : 'T -> 'T -> bool

The custom equality relation. It receives the tested successful value first and the reference successful value second.

Returns: CheckExpectation<'Args, 'T, 'T>

A reusable expectation that delegates successful-value comparison to comparer.

Example

 type Person = { Name: string; Age: int }

 Check.should(
     CheckExpectation.equalWith (fun actual expected -> actual.Age = expected.Age),
     (fun n -> { Name = $"ref-{n}"; Age = n }),
     <@ fun n -> { Name = $"actual-{n}"; Age = n } @>)
type Person = { Name: string Age: int }
Multiple items
val string: value: 'T -> string

--------------------
type string = System.String
Multiple items
val int: value: 'T -> int (requires member op_Explicit)

--------------------
type int = int32

--------------------
type int<'Measure> = int

CheckExpectation.isFalse

Full Usage: CheckExpectation.isFalse

Returns: CheckExpectation<'Args, bool, bool> A reusable bool expectation for “both sides are false”.

Builds a bool expectation that requires the tested code and reference to be false.

Returns: CheckExpectation<'Args, bool, bool>

A reusable bool expectation for “both sides are false”.

CheckExpectation.isTrue

Full Usage: CheckExpectation.isTrue

Returns: CheckExpectation<'Args, bool, bool> A reusable bool expectation for “both sides are true”.

Builds a bool expectation that requires the tested code and reference to be true.

Returns: CheckExpectation<'Args, bool, bool>

A reusable bool expectation for “both sides are true”.

CheckExpectation.orElse a b

Full Usage: CheckExpectation.orElse a b

Parameters:
    a : CheckExpectation<'Args, 'Actual, 'Expected> - The first alternative expectation.
    b : CheckExpectation<'Args, 'Actual, 'Expected> - The second alternative expectation.

Returns: CheckExpectation<'Args, 'Actual, 'Expected> A reusable expectation that succeeds when either input expectation succeeds.

Combines two expectations so that either one may succeed.

a : CheckExpectation<'Args, 'Actual, 'Expected>

The first alternative expectation.

b : CheckExpectation<'Args, 'Actual, 'Expected>

The second alternative expectation.

Returns: CheckExpectation<'Args, 'Actual, 'Expected>

A reusable expectation that succeeds when either input expectation succeeds.

CheckExpectation.satisfyObservedWith description predicate

Full Usage: CheckExpectation.satisfyObservedWith description predicate

Parameters:
    description : string - A short human-readable description of the relation.
    predicate : 'Args -> Observed<'Actual> -> Observed<'Expected> -> bool - The predicate that receives generated arguments and both fully observed outcomes, including exceptions.

Returns: CheckExpectation<'Args, 'Actual, 'Expected> A reusable observed-outcome expectation.

Builds an expectation from a predicate over fully observed outcomes, including exceptions.

description : string

A short human-readable description of the relation.

predicate : 'Args -> Observed<'Actual> -> Observed<'Expected> -> bool

The predicate that receives generated arguments and both fully observed outcomes, including exceptions.

Returns: CheckExpectation<'Args, 'Actual, 'Expected>

A reusable observed-outcome expectation.

CheckExpectation.satisfyWith description predicate

Full Usage: CheckExpectation.satisfyWith description predicate

Parameters:
    description : string - A short human-readable description of the relation.
    predicate : 'Args -> 'Actual -> 'Expected -> bool - The predicate that receives generated arguments, the tested successful value, and the reference successful value. It is only called when both sides returned successfully.

Returns: CheckExpectation<'Args, 'Actual, 'Expected> A reusable successful-value expectation.

Builds an expectation from a predicate over successful values only.

description : string

A short human-readable description of the relation.

predicate : 'Args -> 'Actual -> 'Expected -> bool

The predicate that receives generated arguments, the tested successful value, and the reference successful value. It is only called when both sides returned successfully.

Returns: CheckExpectation<'Args, 'Actual, 'Expected>

A reusable successful-value expectation.

CheckExpectation.throwsSameExceptionType

Full Usage: CheckExpectation.throwsSameExceptionType

Returns: CheckExpectation<'Args, 'Actual, 'Expected> A reusable expectation for exception-shape comparisons. It succeeds only when both sides throw and the thrown exception types match.

Builds an expectation that requires both implementations to throw the same exception type.

Returns: CheckExpectation<'Args, 'Actual, 'Expected>

A reusable expectation for exception-shape comparisons. It succeeds only when both sides throw and the thrown exception types match.

Example

 Check.should(
     CheckExpectation.throwsSameExceptionType,
     (fun (n: int) -> 10 / (n - n)),
     <@ fun n -> 20 / (n - n) @>)
Multiple items
val int: value: 'T -> int (requires member op_Explicit)

--------------------
type int = int32

--------------------
type int<'Measure> = int

Type something to start searching.