Expectation

public protocol Expectation

Undocumented

  • Undocumented

    Declaration

    Swift

    associatedtype Value
  • Undocumented

    Declaration

    Swift

    var expression: Expression<Value> { get }
  • The status of the test after predicates have been evaluated.

    This property can be used for changing test behavior based whether an expectation has passed.

    In the below example, we perform additional tests on an array only if it has enough elements.

    if expect(array).to(haveCount(10)).status == .passed {
       expect(array[9]).to(...)
    }
    

    Remark

    Similar functionality can be achieved using the onFailure(throw:) method.

    Declaration

    Swift

    var status: ExpectationStatus { get }
  • Takes the result of a test and passes it to the assertion handler.

    Declaration

    Swift

    @discardableResult
    func verify(_ pass: Bool, _ message: FailureMessage) -> Self

    Return Value

    An updated Expression with the result of the test applied to the status property.

  • to(_:description:) Extension method

    Tests the actual value using a matcher to match.

    Declaration

    Swift

    @discardableResult
    public func to(_ predicate: Predicate<Value>, description: String? = nil) -> Self
  • toNot(_:description:) Extension method

    Tests the actual value using a matcher to not match.

    Declaration

    Swift

    @discardableResult
    public func toNot(_ predicate: Predicate<Value>, description: String? = nil) -> Self
  • notTo(_:description:) Extension method

    Tests the actual value using a matcher to not match.

    Alias to toNot().

    Declaration

    Swift

    @discardableResult
    public func notTo(_ predicate: Predicate<Value>, description: String? = nil) -> Self
  • onFailure(throw:) Extension method

    Throws the supplied error if the expectation has previously failed.

    This provides a mechanism for halting tests when a failure occurs. This can be used in conjunction with Quick.StopTest to halt a test when a failure would cause subsequent test code to fail.

    In the below example, the test will stop in the first line if array.count == 5 rather than crash on the second line.

    try expect(array).to(haveCount(10)).onFailure(throw: StopTest.silently)
    expect(array[9]).to(...)
    

    Warning

    This method MUST be called after a predicate method like to or not. Otherwise, this expectation will be in an indeterminate state and will unconditionally log an error.

    Remark

    Similar functionality can be achieved using the status property.

    Declaration

    Swift

    public func onFailure(throw error: Error) throws