Skip to content

get method on Wrapper #1298

Closed
Closed
@tomasbjerre

Description

@tomasbjerre

What problem does this feature solve?

Sometimes you "look for something" and sometimes you "get something". If you look for something, it may not exists. If you get something, it is an error if it does not exist.

In my test cases I want to use a get method on the wrapper. And get a clear error describing that what I was looking for cannot be found.

What does the proposed API look like?

In Wrapper.js

  /**
   * Gets first node in tree of the current wrapper that
   * matches the provided selector.
   */
  get(rawSelector: Selector): Wrapper {
    const found = find(rawSelector)
    if (found instanceof ErrorWrapper) {
      throw new Error(`Unable to find ${rawSelector} within: ${this.html()}`)
    }
    return found
  }

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions