Skip to content

How to check for WrapperLike type #2208

Closed Answered by cexbrayat
moohere asked this question in Q&A
Discussion options

You must be logged in to vote

Ha yes I understand why. You're trying to find components using a string selector, which loses all type-safety and returns a WrapperLike.

You can make it work with something like:

function testIdPlugin(wrapper: VueWrapper | DOMWrapper<Node>): {
  findByTestId: (name: string, isComponent: boolean) => BaseWrapper<Node>;
} {
  return {
    findByTestId(name: string, isComponent: boolean) {
      return isComponent
        ? wrapper.findComponent(`[data-test-id='${name}']`) as BaseWrapper<Node>
        : wrapper.find(`[data-test-id='${name}']`);
    }
  };
}

But to be honest with you, I think you're shooting yourself in the foot by trying to do this if you care about type safety.
The "type-sa…

Replies: 1 comment 7 replies

Comment options

You must be logged in to vote
7 replies
@moohere
Comment options

@cexbrayat
Comment options

@moohere
Comment options

@cexbrayat
Comment options

Answer selected by moohere
@moohere
Comment options

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
2 participants