Code Monkey home page Code Monkey logo

Comments (15)

eddyerburgh avatar eddyerburgh commented on May 18, 2024 2

I think we should just add support for refs at the moment ☺

from vue-test-utils.

matt-oconnell avatar matt-oconnell commented on May 18, 2024 2

@eddyerburgh To make it a little more concise, how do you feel about:

find({ ref: 'myRefName' })

from vue-test-utils.

eddyerburgh avatar eddyerburgh commented on May 18, 2024 1

Ah that's a good point.

If we add this then we need to:

  • Update all methods that take a selector: is, contains, find, findAll
  • Update the selectors page to include the refs object
  • Link to the selectors page in the validation error

That's a fairly big change. Before we go further, I would like some input from others.

Do we want to extend the selector to include { refs: 'refName' }

from vue-test-utils.

eddyerburgh avatar eddyerburgh commented on May 18, 2024

I think this is a good idea, but I don't think we should add an extra method.

We could extend find and findAll, so that they could take a selector object.

find({
  selector: 'refs',
  value: 'value' 
})

Then we could extend it to other selectors, like props.

find({
  selector: 'props',
  value: 'value' 
})

from vue-test-utils.

matt-oconnell avatar matt-oconnell commented on May 18, 2024

I wonder how many alternate use cases we would have for a selector other than CSS, component name, or $ref. I'm not sure if component with prop: xwould ever be used as a selector, but I could be wrong.

from vue-test-utils.

matt-oconnell avatar matt-oconnell commented on May 18, 2024

But, if we do want to go with the selector/value find/findAll functions, I could start a PR. Initially it could look for $props / $refs. I guess the tough part would be matching $props because the values could be any

from vue-test-utils.

eddyerburgh avatar eddyerburgh commented on May 18, 2024

Yep that looks good πŸ‘

from vue-test-utils.

matt-oconnell avatar matt-oconnell commented on May 18, 2024

Great, updating the PR to reflect this. Currently, the validation error messages for find/findAll display: wrapper.find/findAll() must be passed a valid CSS selector or a Vue constructor. As we update the API to accept this new options object, how should we refer to it?

If we're going to start with refs for now, we could use:

wrapper.find() must be passed a valid CSS selector, Vue constructor, or ref object

Or wrapper.find() must be passed a valid CSS selector, Vue constructor, or options object

My only concern with the latter is that it may be too vague.

from vue-test-utils.

matt-oconnell avatar matt-oconnell commented on May 18, 2024

So, one thing other thing to note: When selecting $refs, we rely on the $ref property to be available on the wrapper.vm, because we want to limit the results to this scope. This is one of the benefits of $refs. If we are using a wrapper on a non-Vue HTML Element, we should not allow selecting by $ref.

from vue-test-utils.

eddyerburgh avatar eddyerburgh commented on May 18, 2024

from vue-test-utils.

skray avatar skray commented on May 18, 2024

The PR for this change mentioned wanting some feedback from the community, so I thought I'd chime in.

This would be great to have, I liked the initial suggestion of having wrapper.ref, but I understand from a consistency standpoint why you'd want to extend the current finders. The current recommendation of using wrapper.find({refs: 'refName'}) feels comfortable to me.

from vue-test-utils.

eddyerburgh avatar eddyerburgh commented on May 18, 2024

Thanks for the feedback @skray.

I'm happy for this work to continue. @matt-oconnell do you have any blockers?

from vue-test-utils.

matt-oconnell avatar matt-oconnell commented on May 18, 2024

This is pretty much fully implemented in the corresponding PR. The blocker was that the Flow types were invalid (specifically Component,) so this PR fails the type check unless any is used

from vue-test-utils.

eddyerburgh avatar eddyerburgh commented on May 18, 2024

I think we'll have to use any until proper flowtypes are exported from Vue β€” vuejs/vue#5027

from vue-test-utils.

eddyerburgh avatar eddyerburgh commented on May 18, 2024

This can be closed, released in 1.0.0-beta.5

from vue-test-utils.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    πŸ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. πŸ“ŠπŸ“ˆπŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❀️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.