Code Monkey home page Code Monkey logo

Comments (7)

dfcook avatar dfcook commented on May 18, 2024 1

I suppose that's possible but I went for a middle path between dogmatism and pragmatism. This lets people control the initial setup then test against the DOM. If they want to start accessing the router directly then they're free to miss the point of such testing 😆

from vue-testing-library.

dfcook avatar dfcook commented on May 18, 2024

Hi, if you look at the examples around routing the idea is that you find the link on the page and fire the click event on it.

Would this suit your use case?

from vue-testing-library.

amcsi avatar amcsi commented on May 18, 2024

@dfcook Oh, I do understand that's what x-testing-library is meant to do... Actually, let me change the question:

How can I set the initial router route?

Although according to this library I should be changing routes by clicking on the appropriate buttons, but I think I should be able to at least set the initial route, because it's a valid thing for a user to "land" on a certain page.

from vue-testing-library.

dfcook avatar dfcook commented on May 18, 2024

I was thinking there must be some way of configuring the routes but it appears there isn't, a limitation of vue-router, see this issue:

vuejs/vue-router#866

The obvious way to get around this is to expose the created router in the object returned from render but I'm not sure if that's a bit leaky given the aims of the dom-testing-library.

Do you have any thoughts yourself on how you'd like it to work? I mean we could accept a default router property on the routes parameter and do a push immediately after rendering?

from vue-testing-library.

amcsi avatar amcsi commented on May 18, 2024

@dfcook the way I imagined it is that in the configurationCb, a function would be exposed that would allow me to change the route only 1 time, and that too only for the duration of configurationCb (it would stop working afterward). That would ensure that I could only change the route initially, but not later.
...or maybe you could have the same thing, but as a "route" string needed to be passed to a property of RenderOptions. I can see that react-testing-library uses a route property: https://github.com/kentcdodds/react-testing-library/blob/master/examples/__tests__/react-router.js#L38

from vue-testing-library.

dfcook avatar dfcook commented on May 18, 2024

I've pushed 0.16.0 which adds the constructed store and router to the configuration callback, this allows a router to be pushed before the component is rendered.

https://github.com/testing-library/vue-testing-library/blob/master/src/__tests__/vue-router.js

from vue-testing-library.

amcsi avatar amcsi commented on May 18, 2024

@dfcook thanks, that's great! But are you not worried that now one can have access to the router at any time by saving it to an outer variable from the init callback? I said the examples I said, because in those ways you would not have to expose the router.

from vue-testing-library.

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.