Skip to main content

externalformat

Callable

  • format(config: { markQuestions: boolean }): (templates: TemplateStringsArray, ...placeholders: Answerable<any>[]) => string

  • format is a factory function returning a tag function that produces a human-readable string description of a template containing one or more answerables.

    Typically, you'll want to use d and f shorthands instead, or the modern alternative - the:

    • the d function works best for generating a static description of a parameterised Activity
    • the f function is better suited for debugging
    • the the function works best for generating a dynamic description of a parameterised Activity
    Use `the` instead of `format`

    format, d and f are the original Serenity/JS string formatting functions, still present in the framework for backwards compatibility purposes.

    To generate a dynamic description of a Question or Interaction, use the function instead.

    Using format

    import { format, Question } from '@serenity-js/core'

    const someQuestion = () =>
    Question.about('some question', actor => 'some value')

    format({ markQuestions: true }) `actor answers ${ question() }`
    // returns: actor answers <<some question>>

    format({ markQuestions: false }) `actor answers ${ question() }`
    // returns: actor answers some question

    Using d

    import { d, Question } from '@serenity-js/core'

    const someQuestion = () =>
    Question.about('some question', actor => 'some value')

    d`actor answers ${ question() }`
    // returns: actor answers <<some question>>

    Using f

    import { f, Question } from '@serenity-js/core'

    const someQuestion = () =>
    Question.about('some question', actor => 'some value')

    f`actor answers ${ question() }`
    // returns: actor answers <<some question>>

    format({ markQuestions: false }) `actor answers ${ question() }`
    // returns: actor answers <<some question>>

    Parameters

    • externalconfig: { markQuestions: boolean }

      markQuestions: boolean - if set to true, descriptions of questions passed in as arguments will be surrounded with double angled brackets, i.e. <<description>>

      • externalmarkQuestions: boolean

    Returns (templates: TemplateStringsArray, ...placeholders: Answerable<any>[]) => string

      • (templates: TemplateStringsArray, ...placeholders: Answerable<any>[]): string
      • Parameters

        • externaltemplates: TemplateStringsArray
        • externalrest...placeholders: Answerable<any>[]

        Returns string