Skip to main content

externalMetaList <Supported_Context_Type, Item_Type>

Serenity/JS Screenplay Pattern-style wrapper around a ChainableMetaQuestion representing a collection that can be resolved in Supported_Context_Type of another Question.

For example, PageElements.located returns MetaList<PageElement>, which allows for the collection of page elements to be resolved in the context of dynamically-provided root element.

import { By, PageElements, PageElement } from '@serenity-js/web'

const firstLabel = () =>
PageElements.located(By.css('label'))
.first()
.describedAs('first label')

const exampleForm = () =>
PageElement.located(By.css('form#example1'))
.describedAs('example form')

const anotherExampleForm = () =>
PageElement.located(By.css('form#example2'))
.describedAs('another example form')

// Next, you can compose the above questions dynamically with various "contexts":
// firstLabel().of(exampleForm())
// firstLabel().of(anotherExampleForm())

Hierarchy

  • List<Item_Type>
    • MetaList

Implements

Index

Constructors

externalconstructor

  • Type parameters

    • Supported_Context_Type
    • Item_Type

    Parameters

    Returns MetaList<Supported_Context_Type, Item_Type>

Methods

externaldescribedAs

  • Changes the description of this object, as returned by Describable.describedBy and Describable.toString.


    Parameters

    • externaldescription: Answerable<string> | MetaQuestion<Item_Type[], Question<Promise<string>>>

      Replaces the current description according to the following rules:

      • If description is an Answerable, it replaces the current description
      • If description is a MetaQuestion, the current description is passed as context to description.of(context), and the result replaces the current description

    Returns this

externaldescribedBy

  • Resolves the description of this object in the context of the provided actor.


    Parameters

    Returns Promise<string>

externaltoString

  • toString(): string
  • Returns a human-readable description of this object.


    Returns string

externalforEach

  • forEach(callback: (current: CurrentItem<Item_Type>, index: number, items: Item_Type[]) => void | Promise<void>): Task
  • Parameters

    • externalcallback: (current: CurrentItem<Item_Type>, index: number, items: Item_Type[]) => void | Promise<void>

      Returns Task

    externalansweredBy

    externalof

    • of(context: Answerable<Supported_Context_Type>): MetaList<Supported_Context_Type, Item_Type>
    • Answers the given ChainableMetaQuestion in the context of another Answerable and returns another ChainableMetaQuestion ready for further chaining.

      Learn more


      Parameters

      • externalcontext: Answerable<Supported_Context_Type>

      Returns MetaList<Supported_Context_Type, Item_Type>

    externaleachMappedTo

    • eachMappedTo<Mapped_Item_Type>(question: MetaQuestion<Item_Type, Question<Mapped_Item_Type | Promise<Mapped_Item_Type>>>): MetaList<Supported_Context_Type, Mapped_Item_Type>
    • Type parameters

      • Mapped_Item_Type

      Parameters

      Returns MetaList<Supported_Context_Type, Mapped_Item_Type>

    externalwhere

    • Parameters

      Returns MetaList<Supported_Context_Type, Item_Type>

    externalcount

    externalfirst

    externallast

    externalnth

    • Parameters

      • externalindex: number

      Returns MetaQuestionAdapter<Supported_Context_Type, Item_Type>

    Screenplay Pattern

    publicexternalas

    • Maps this question's resolved answer to a QuestionAdapter of a different type.

      Provide a function to transform the resolved answer:

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

      const number = Question.about('number returned as text', () => '42')
      .as(Number)

      const name = Question.about('name with whitespace', () => ' Alice ')
      .as(value => value.trim())

      const firstValue = Question.about('available values', () => ['first', 'second'])
      .as(values => values[0])

      Alternatively, provide a constructor. When you call .as(MyClass), Serenity/JS passes the resolved answer as MyClass's sole constructor argument. This is particularly useful when wrapping a mounted UI component in an Interaction Object for component testing:

      const card = story('components/UserCard/Default', { name: 'Alice' }).as(UserCard)

      To distinguish a mapping function from a constructor, Serenity/JS calls the mapping as a function first. If that throws a TypeError and the mapping has a prototype (indicating an ES6 class), Serenity/JS retries with new. This preserves the primitive result of Number(42), rather than producing a Number wrapper object.

      Learn more


      Type parameters

      • O

      Parameters

      • externalmapping: (answer: Item_Type[]) => O | Promise<O>

        A function that transforms the resolved answer, or a constructor that receives it as its sole argument.

        Returns QuestionAdapter<O>

        A QuestionAdapter that resolves to the mapped answer.