-
Notifications
You must be signed in to change notification settings - Fork 249
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
Unit testing a metaInfo() statement #493
Comments
Create a localVue instance with the vue-meta plugin installed, use that when mounting the component and then call Have a look at our unit tests for more/other info: https://github.com/nuxt/vue-meta/blob/master/test/unit/components.test.js |
Final solution for those we would arrive here:
Thx again, Im closing the issue :) |
Do you plan to test more then your example shows? Because if you dont, then it seems that you are mostly testing whether vue-meta still works as expected. Which we already do for you on every commit/release. So you could say that what you are testing is whether 1 + 1 is still really 2. vue-meta merges the meta information of all components on the page, which means that it would make sense if you would be doing a full mount to test what metainfo the combination of your child components returns. But testing a shallow mount on a single component against a single expected title value doesnt seem that useful to me 🤔 |
Hello, |
Was looking to close the gap on some unit test coverage with a Nuxt.js project and this helped; thanks @pimlie. 👏 For those working with Nuxt, you'll also have to make sure to specify the import { shallowMount, createLocalVue } from '@vue/test-utils'
import VueMeta from 'vue-meta'
// ...
const localVue = createLocalVue();
localVue.use(VueMeta, { keyName: 'head' }); Hopefully this helps. 👍 |
@haversnail would you be able to post your full code? im struggling to understand this with a nuxt project |
import { shallowMount, createLocalVue } from '@vue/test-utils'
import VueMeta from 'vue-meta'
import Component from '@/components/Component.vue'
const localVue = createLocalVue()
localVue.use(VueMeta)
describe('Component.vue', () => {
it('should do kewl things', () => {
const wrapper = shallowMount(Component, {})
// console.log(wrapper.vm.$meta) // undefined
})
}) |
@sinjaz I think it's solved, but I'll post it just in case. describe('Component.vue', () => {
it('should do kewl things', () => {
const wrapper = shallowMount(Component, { localVue })
const meta = wrapper.vm.$meta().refresh();
console.log(meta.metaInfo);
})
}) |
Anyone with |
Thanks. This worked for me. |
Hello,
Let's say I have this vueJS component:
How would you unit test that the meta title of the page is correctly set? I couldn't fiund the way to trigger the function within the following test:
Thank you very much :)
The text was updated successfully, but these errors were encountered: