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

router-link and router-view stub components #224

Closed
eddyerburgh opened this issue Dec 3, 2017 · 2 comments · Fixed by #366
Closed

router-link and router-view stub components #224

eddyerburgh opened this issue Dec 3, 2017 · 2 comments · Fixed by #366

Comments

@eddyerburgh
Copy link
Member

eddyerburgh commented Dec 3, 2017

Should we include router-view and router-link stub components?

Currently I have to do something like this to test the text rendered in a router-link:

const RouterLink = {
  name: 'router-link',
  render: function (h) {
    return h('div', this.$slots.default)
  },
  props: ['to']
}

const wrapper = shallow(Component, {
  stubs: {
    RouterLink
  },
})

expect(wrapper.find(RouterLink).props().to).toBe('/best/')
expect(wrapper.find(RouterLink).text()).toBe('best')

We could extract that logic into a component exported by vue-test-utils:

import { RouterLink } from 'vue-test-utils'

const wrapper = shallow(Component, {
  stubs: {
    RouterLink
  },
})

expect(wrapper.find(RouterLink).props().to).toBe('/best/')
expect(wrapper.find(RouterLink).text()).toBe('best')
@sandiya-baranidaran
Copy link

sandiya-baranidaran commented Dec 13, 2017

Hi,
Thank you for your post.

I have my navMenu.vue.html as Follows:

<div class="navbar-collapse collapse">
                <ul class="nav navbar-nav">
                    <li>
                        <router-link to="/" :exact="false" router-link-active="true" >
                            <span class="fa fa-upload"></span> Upload
                        </router-link>
                    </li>
                    <li>
                        <router-link to="/counter">
                            <span class="fa fa-cog"></span> Admin
                        </router-link>
                    </li>
                </ul>
            </div>

and I would like to test the router-link. As your doesnt mention on how to test specific router at a time. Please could you advise on how to do this.I am using vue-test-utils. I am very new to Jasmine and Karma.Please help.

@lmiller1990
Copy link
Member

This seems like a good feature, consider vue has an official router + flux store, the utils should reflect that.

Maybe we can also do something for vuex? I find myself writing a ton of boilerplate for components using a vuex store, might be something we could consider including.

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.

3 participants