-
Notifications
You must be signed in to change notification settings - Fork 245
Closed
Description
Hello,
Let's say I have this vueJS component:
export default {
name: "Record",
id: 'ABA',
methods: {
// @vuese
// Method to build and return the page title to be included as a metadata
getTitle: function(){
return 'MywebSite | ' + this.$route.params['id']
}
},
// @vuese
// set the meta-data of the page
metaInfo() {
return {
title: this.getTitle()
}
}
}
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:
import { shallowMount } from '@vue/test-utils'
import Record from './Record.vue'
const $route = {
path: '/',
params: {
id: '120'
}
};
describe('Record.vue', function() {
// Set up the wrapper
let wrapper;
beforeEach(() => {
wrapper = shallowMount(Record, {
mocks: {$route}
});
});
const title = 'MywebSite | 120 ' ;
it('can be instantiated', () => {
expect(wrapper.name()).toMatch('Record');
expect(wrapper.attributes('id')).toMatch('ABA');
});
it('has a getTitle() method that returns the page title', () => {
expect(wrapper.vm.getTitle()).toBe(title);
});
it('has its meta title correctly set', () => {
// test metaInfo() here
});
})
Thank you very much :)
danieldanielecki
Metadata
Metadata
Assignees
Labels
No labels