interface ScenarioClause {
    functionSubject(value: Function): SubjectClause;
    promiseSubject(value: PromiseSubjectValue): SubjectClause;
    subject(value: EagerSubjectValue): SubjectClause;
}

Methods

  • Variation of subject that does not call the passed function.

    This is especially useful in the case of matchers expecting a function - like .toThrow().

    Parameters

    • value: Function

      A function, that will be passed directly to expect()

    Returns SubjectClause

    .functionSubject(() => {
    throw new Error("Test");
    })
  • Variation of subject that does not perform await on its Promise subject.

    This is especially useful in the case of matchers - like toResolve() - whose subject is not the value returned by the Promise, but the Promise itself.

    Parameters

    Returns SubjectClause

    Promise passed directly:

    .promiseSubject(Promise.resolve(92))
    

    Function returning a Promise:

    .promiseSubject(() => Promise.resolve(92))
    
  • Defines the subject of each test - i.e., the argument of the expect() call.

    Parameters

    • value: EagerSubjectValue

      Can be:

      • a value of any type - when not a Promise or a function - that will be passed to expect()

      • a Promise - that will be awaited to get the expect() argument

      • a function - that will be called to retrieve one of the above types and then behave accordingly

    Returns SubjectClause

    Immediate value:

    .subject(90)
    

    Promise, which will be awaited to get the actual value (in this case, 90)

    .subject(Promise.resolve(90))
    

    Function returning the value:

    .subject(() => 90)
    

    Function returning a Promise that will be awaited after the function call:

    .subject(() => Promise.resolve(90))