Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

get method on Wrapper #1298

Closed
tomasbjerre opened this issue Aug 30, 2019 · 0 comments · Fixed by #1304
Closed

get method on Wrapper #1298

tomasbjerre opened this issue Aug 30, 2019 · 0 comments · Fixed by #1304

Comments

@tomasbjerre
Copy link
Contributor

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
  }
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants