Skip to content

Do not allow calling exists on get and getComponent because it is already implied #176

@angelogulina

Description

@angelogulina

This Issue relates to the discussion started here.

I noticed that get would introduce the same tension with find that it's currently occurring between find and at (on v1) that is, throwing an error. Maybe I am missing some context that justifies the choice and I'd be glad to know more. Further I try to explain why this would seem odd to me.

The docs example suggest a usage of get (note that the example uses getComponent but it's listed under get):

test('get', () => {
  const wrapper = mount(Component)
  expect(() => wrapper.getComponent('p')).toThrowError()
})
  • the assertion does not seem to describe that a p Component is not supposed to be there (to exist)
  • it is rather testing the library internal implementation or at least hardly depending on (the knowledge of) it

For sure using the library requires knowing the API but it should not require knowledge of the internal implementation and this last one should not be the target of a client test. Now,

  • the signature of get suggests it returns a DomWrapper
  • TypeScript would suggest the same
  • similarity with find (stated in the docs) would suggest the same
  • there are only two places I can find to know that get throws an error: the source code and the examples is the code.

I might be wrong and happy to review my thoughts but the source code (which is internal implementation) should not generally be the source of my tests, even less the subject of them. As for the docs, part of my point is that this example should not be there, as it suggests relying on the internal implementation of the method.

If replying to this gets too big, I'ma happy to open an Issue fo this in the v2 repo.

Thanks a lot for your time 🙏 really appreciate it.

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