Header menu logo testify

AssertExpectation Module

Builders and combinators for reusable assertion semantics.

Functions and values

Function or value Description

AssertExpectation.``not`` expectation

Full Usage: AssertExpectation.``not`` expectation

Parameters:
Returns: AssertExpectation<'T> An expectation that succeeds exactly when expectation would fail.

Negates an existing expectation.

expectation : AssertExpectation<'T>

The expectation to invert.

Returns: AssertExpectation<'T>

An expectation that succeeds exactly when expectation would fail.

AssertExpectation.all expectations

Full Usage: AssertExpectation.all expectations

Parameters:
Returns: AssertExpectation<'T> An expectation that succeeds only when every supplied expectation succeeds.

Combines a sequence of expectations so that all of them must succeed.

expectations : AssertExpectation<'T> seq

The expectations to combine.

Returns: AssertExpectation<'T>

An expectation that succeeds only when every supplied expectation succeeds.

Example

 open Testify.AssertOperators

 <@ "MiniLib" @> &&?
     [ AssertExpectation.startsWith "Mini"
       AssertExpectation.endsWith "Lib" ]

AssertExpectation.andAlso a b

Full Usage: AssertExpectation.andAlso a b

Parameters:
Returns: AssertExpectation<'T> An expectation that succeeds only when both input expectations succeed.

Combines two expectations so that both must succeed.

a : AssertExpectation<'T>

The first required expectation.

b : AssertExpectation<'T>

The second required expectation.

Returns: AssertExpectation<'T>

An expectation that succeeds only when both input expectations succeed.

AssertExpectation.any expectations

Full Usage: AssertExpectation.any expectations

Parameters:
Returns: AssertExpectation<'T> An expectation that succeeds when any supplied expectation succeeds.

Combines a sequence of expectations so that at least one of them must succeed.

expectations : AssertExpectation<'T> seq

The expectations to combine.

Returns: AssertExpectation<'T>

An expectation that succeeds when any supplied expectation succeeds.

AssertExpectation.between lowerBound upperBound

Full Usage: AssertExpectation.between lowerBound upperBound

Parameters:
    lowerBound : 'T - The inclusive lower bound.
    upperBound : 'T - The inclusive upper bound.

Returns: AssertExpectation<'T> An expectation that succeeds when the value lies within the supplied range.

Builds an expectation that checks whether a value lies between two inclusive bounds.

lowerBound : 'T

The inclusive lower bound.

upperBound : 'T

The inclusive upper bound.

Returns: AssertExpectation<'T>

An expectation that succeeds when the value lies within the supplied range.

AssertExpectation.contains expectedItem

Full Usage: AssertExpectation.contains expectedItem

Parameters:
    expectedItem : 'T - The item that must be present in the sequence.

Returns: AssertExpectation<'T seq> An expectation for containment checks.

Builds an expectation that checks whether a sequence contains a specific item.

expectedItem : 'T

The item that must be present in the sequence.

Returns: AssertExpectation<'T seq>

An expectation for containment checks.

AssertExpectation.doesNotThrow

Full Usage: AssertExpectation.doesNotThrow

Returns: AssertExpectation<'T> An expectation for successful synchronous evaluation.

Builds an expectation that succeeds when evaluation completes without throwing.

Returns: AssertExpectation<'T>

An expectation for successful synchronous evaluation.

AssertExpectation.doesNotThrowAsync

Full Usage: AssertExpectation.doesNotThrowAsync

Returns: AssertExpectation<'T> An expectation for successful asynchronous evaluation.

Builds an expectation that succeeds when an async or task-based expression completes without throwing.

Returns: AssertExpectation<'T>

An expectation for successful asynchronous evaluation.

AssertExpectation.endsWith suffix

Full Usage: AssertExpectation.endsWith suffix

Parameters:
    suffix : string - The required suffix.

Returns: AssertExpectation<string> An expectation for suffix-based string assertions.

Builds an expectation that checks whether a string ends with a suffix.

suffix : string

The required suffix.

Returns: AssertExpectation<string>

An expectation for suffix-based string assertions.

AssertExpectation.equalBy projection expected

Full Usage: AssertExpectation.equalBy projection expected

Parameters:
    projection : 'T -> 'Key - The projection used to derive the comparison key from both values.
    expected : 'T - The full expected value whose projected key must match the observed one.

Returns: AssertExpectation<'T> An expectation that compares the projected keys using F# equality.

Builds an equality expectation after projecting both the observed and expected values.

projection : 'T -> 'Key

The projection used to derive the comparison key from both values.

expected : 'T

The full expected value whose projected key must match the observed one.

Returns: AssertExpectation<'T>

An expectation that compares the projected keys using F# equality.

Example

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

 <@ { Name = "Tony"; Age = 48 } @>
 |>? AssertExpectation.equalBy (fun person -> person.Age) { Name = "Anthony"; Age = 48 }
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

AssertExpectation.equalByKey projection expectedKey

Full Usage: AssertExpectation.equalByKey projection expectedKey

Parameters:
    projection : 'T -> 'Key - The projection used to derive the comparison key from the observed value.
    expectedKey : 'Key - The projected key that the observed value must match.

Returns: AssertExpectation<'T> An expectation that compares the projected key using F# equality.

Builds an equality expectation after projecting the observed value to a comparison key.

projection : 'T -> 'Key

The projection used to derive the comparison key from the observed value.

expectedKey : 'Key

The projected key that the observed value must match.

Returns: AssertExpectation<'T>

An expectation that compares the projected key using F# equality.

Example

 <@ "Testify" @>
 |>? AssertExpectation.equalByKey String.length 7
module String from Microsoft.FSharp.Core
val length: str: string -> int

AssertExpectation.equalTo expected

Full Usage: AssertExpectation.equalTo expected

Parameters:
    expected : 'T - The value the observed result must equal.

Returns: AssertExpectation<'T> An expectation that uses F# equality for the comparison.

Builds an expectation that checks equality with a fixed expected value.

expected : 'T

The value the observed result must equal.

Returns: AssertExpectation<'T>

An expectation that uses F# equality for the comparison.

Example

 open Testify.AssertOperators

 <@ 6 * 7 @> |>? AssertExpectation.equalTo 42

AssertExpectation.equalToWithDiff diffOptions expected

Full Usage: AssertExpectation.equalToWithDiff diffOptions expected

Parameters:
    diffOptions : DiffOptions - The diff configuration to use when formatting a mismatch.
    expected : 'T - The value the observed result must equal.

Returns: AssertExpectation<'T> An expectation that uses F# equality and enriched diff output.

Builds an equality expectation that uses the supplied diff options when a mismatch is rendered.

diffOptions : DiffOptions

The diff configuration to use when formatting a mismatch.

expected : 'T

The value the observed result must equal.

Returns: AssertExpectation<'T>

An expectation that uses F# equality and enriched diff output.

AssertExpectation.equalWith comparer expected

Full Usage: AssertExpectation.equalWith comparer expected

Parameters:
    comparer : 'T -> 'T -> bool - The comparison function used to compare the observed and expected values.
    expected : 'T - The value the observed result must match according to comparer.

Returns: AssertExpectation<'T> An expectation that delegates equality to the supplied comparer.

Builds an equality expectation using a custom comparison function.

comparer : 'T -> 'T -> bool

The comparison function used to compare the observed and expected values.

expected : 'T

The value the observed result must match according to comparer.

Returns: AssertExpectation<'T>

An expectation that delegates equality to the supplied comparer.

Example

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

 <@ { Name = "Tony"; Age = 48 } @>
 |>? AssertExpectation.equalWith (fun actual expected -> actual.Age = expected.Age) { Name = "Anthony"; Age = 48 }
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

AssertExpectation.greaterThan expected

Full Usage: AssertExpectation.greaterThan expected

Parameters:
    expected : 'T - The exclusive lower bound.

Returns: AssertExpectation<'T> An expectation that succeeds when the value is greater than expected.

Builds an expectation that checks whether a value is greater than a bound.

expected : 'T

The exclusive lower bound.

Returns: AssertExpectation<'T>

An expectation that succeeds when the value is greater than expected.

AssertExpectation.greaterThanOrEqualTo expected

Full Usage: AssertExpectation.greaterThanOrEqualTo expected

Parameters:
    expected : 'T - The inclusive lower bound.

Returns: AssertExpectation<'T> An expectation that succeeds when the value is greater than or equal to expected.

Builds an expectation that checks whether a value is greater than or equal to a bound.

expected : 'T

The inclusive lower bound.

Returns: AssertExpectation<'T>

An expectation that succeeds when the value is greater than or equal to expected.

AssertExpectation.hasLength expectedLength

Full Usage: AssertExpectation.hasLength expectedLength

Parameters:
    expectedLength : int - The required number of elements.

Returns: AssertExpectation<'T seq> An expectation for sequence length checks.

Builds an expectation that checks whether a sequence has a specific length.

expectedLength : int

The required number of elements.

Returns: AssertExpectation<'T seq>

An expectation for sequence length checks.

AssertExpectation.isError

Full Usage: AssertExpectation.isError

Returns: AssertExpectation<Result<'T, 'TError>> An expectation for failing Result values.

Builds an expectation that requires a result value to be Error _.

Returns: AssertExpectation<Result<'T, 'TError>>

An expectation for failing Result values.

AssertExpectation.isFalse

Full Usage: AssertExpectation.isFalse

Returns: AssertExpectation<bool> An expectation for falsy boolean assertions.

Builds an expectation that requires a boolean value to be false.

Returns: AssertExpectation<bool>

An expectation for falsy boolean assertions.

AssertExpectation.isNone

Full Usage: AssertExpectation.isNone

Returns: AssertExpectation<'T option> An expectation for missing option values.

Builds an expectation that requires an option to be None.

Returns: AssertExpectation<'T option>

An expectation for missing option values.

AssertExpectation.isOk

Full Usage: AssertExpectation.isOk

Returns: AssertExpectation<Result<'T, 'TError>> An expectation for successful Result values.

Builds an expectation that requires a result value to be Ok _.

Returns: AssertExpectation<Result<'T, 'TError>>

An expectation for successful Result values.

AssertExpectation.isSome

Full Usage: AssertExpectation.isSome

Returns: AssertExpectation<'T option> An expectation for present option values.

Builds an expectation that requires an option to be Some _.

Returns: AssertExpectation<'T option>

An expectation for present option values.

AssertExpectation.isTrue

Full Usage: AssertExpectation.isTrue

Returns: AssertExpectation<bool> An expectation for truthy boolean assertions.

Builds an expectation that requires a boolean value to be true.

Returns: AssertExpectation<bool>

An expectation for truthy boolean assertions.

AssertExpectation.lessThan expected

Full Usage: AssertExpectation.lessThan expected

Parameters:
    expected : 'T - The exclusive upper bound.

Returns: AssertExpectation<'T> An expectation that succeeds when the value is smaller than expected.

Builds an expectation that checks whether a value is less than a bound.

expected : 'T

The exclusive upper bound.

Returns: AssertExpectation<'T>

An expectation that succeeds when the value is smaller than expected.

AssertExpectation.lessThanOrEqualTo expected

Full Usage: AssertExpectation.lessThanOrEqualTo expected

Parameters:
    expected : 'T - The inclusive upper bound.

Returns: AssertExpectation<'T> An expectation that succeeds when the value is smaller than or equal to expected.

Builds an expectation that checks whether a value is less than or equal to a bound.

expected : 'T

The inclusive upper bound.

Returns: AssertExpectation<'T>

An expectation that succeeds when the value is smaller than or equal to expected.

AssertExpectation.notEqualTo expected

Full Usage: AssertExpectation.notEqualTo expected

Parameters:
    expected : 'T - The value the observed result must not equal.

Returns: AssertExpectation<'T> An expectation that succeeds when the observed value differs from expected.

Builds an expectation that checks inequality against a fixed value.

expected : 'T

The value the observed result must not equal.

Returns: AssertExpectation<'T>

An expectation that succeeds when the observed value differs from expected.

AssertExpectation.orElse a b

Full Usage: AssertExpectation.orElse a b

Parameters:
Returns: AssertExpectation<'T> An expectation that succeeds when either input expectation succeeds.

Combines two expectations so that either one may succeed.

a : AssertExpectation<'T>

The first alternative expectation.

b : AssertExpectation<'T>

The second alternative expectation.

Returns: AssertExpectation<'T>

An expectation that succeeds when either input expectation succeeds.

AssertExpectation.satisfy description predicate

Full Usage: AssertExpectation.satisfy description predicate

Parameters:
    description : string - A short human-readable description of the expected behavior.
    predicate : 'T -> bool - The predicate that must return true for successful observed values.

Returns: AssertExpectation<'T> A reusable expectation based on the supplied predicate.

Builds an expectation from a predicate over successful values.

Use satisfy when you only care about the resulting value. If you need to inspect thrown exceptions as well, use satisfyObserved.

description : string

A short human-readable description of the expected behavior.

predicate : 'T -> bool

The predicate that must return true for successful observed values.

Returns: AssertExpectation<'T>

A reusable expectation based on the supplied predicate.

AssertExpectation.satisfyObserved description predicate

Full Usage: AssertExpectation.satisfyObserved description predicate

Parameters:
    description : string - A short human-readable description of the expected behavior.
    predicate : Observed<'T> -> bool - The predicate that receives the full Observed value, including exceptions.

Returns: AssertExpectation<'T> A reusable expectation based on the supplied observed-result predicate.

Builds an expectation from a predicate over the fully observed result.

This is the most flexible expectation builder because it can inspect both returned values and thrown exceptions.

description : string

A short human-readable description of the expected behavior.

predicate : Observed<'T> -> bool

The predicate that receives the full Observed value, including exceptions.

Returns: AssertExpectation<'T>

A reusable expectation based on the supplied observed-result predicate.

AssertExpectation.sequenceEqual expected

Full Usage: AssertExpectation.sequenceEqual expected

Parameters:
    expected : 'T seq - The expected sequence contents.

Returns: AssertExpectation<'T seq> An expectation for sequence equality.

Builds an expectation that checks whether two sequences have the same elements in the same order.

expected : 'T seq

The expected sequence contents.

Returns: AssertExpectation<'T seq>

An expectation for sequence equality.

AssertExpectation.startsWith prefix

Full Usage: AssertExpectation.startsWith prefix

Parameters:
    prefix : string - The required prefix.

Returns: AssertExpectation<string> An expectation for prefix-based string assertions.

Builds an expectation that checks whether a string starts with a prefix.

prefix : string

The required prefix.

Returns: AssertExpectation<string>

An expectation for prefix-based string assertions.

AssertExpectation.throws

Full Usage: AssertExpectation.throws

Returns: AssertExpectation<'T> An expectation that checks the thrown exception type.

Builds an expectation that succeeds when evaluation throws a specific exception type.

Returns: AssertExpectation<'T>

An expectation that checks the thrown exception type.

Example

 open Testify.AssertOperators

 <@ 1 / 0 @> |>? AssertExpectation.throws<int, System.DivideByZeroException>
Multiple items
val int: value: 'T -> int (requires member op_Explicit)

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

--------------------
type int<'Measure> = int
namespace System
Multiple items
type DivideByZeroException = inherit ArithmeticException new: unit -> unit + 2 overloads
<summary>The exception that is thrown when there is an attempt to divide an integral or <see cref="T:System.Decimal" /> value by zero.</summary>

--------------------
System.DivideByZeroException() : System.DivideByZeroException
System.DivideByZeroException(message: string) : System.DivideByZeroException
System.DivideByZeroException(message: string, innerException: exn) : System.DivideByZeroException

AssertExpectation.throwsAny

Full Usage: AssertExpectation.throwsAny

Returns: AssertExpectation<'T> An expectation for exception-based assertions.

Builds an expectation that succeeds when evaluation throws any exception.

Returns: AssertExpectation<'T>

An expectation for exception-based assertions.

AssertExpectation.throwsAsync

Full Usage: AssertExpectation.throwsAsync

Returns: AssertExpectation<'T> An expectation that checks the thrown asynchronous exception type.

Builds an expectation that succeeds when an async or task-based expression throws a specific exception type.

Returns: AssertExpectation<'T>

An expectation that checks the thrown asynchronous exception type.

Type something to start searching.