Expectation

public protocol Expectation

Undocumented

  • Undocumented

    Declaration

    Swift

    var location: SourceLocation { get }
  • The status of the test after matchers 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.

  • 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 matcher 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