Currently, I am delving into the world of Vue.js. In my journey, I have crafted a plugin that takes the form of:
source/myPlugin.js
const MyPlugin = {
install: function(Vue, options) {
console.log('installing my plugin');
Vue.myMethod = function() {
};
}
}
For the purpose of testing this plugin, I decided to use Jest. However, my mind is open to exploring other testing frameworks. As of now, I have laid out the following structure in my test/myPlugin.test.js
file:
test/myPlugin.test.js
const Vue = require('vue/dist/vue');
const MyPlugin = require('../source/myPlugin');
Vue.use(MyPlugin);
describe('MyPlugin', () => {
let vm;
beforeEach(() => {
const template = `<div id="app"></div>`;
vm = new Vue({
template
}).$mount();
});
it('should run', () => {
Vue.myMethod();
expect(true).toEqual(true);
});
});
Upon running the test with Jest, my expectation was to witness "installing my plugin" displayed in the console. Unfortunately, this was not the case as the output indicated:
TypeError: Vue.myMethod is not a function
Where could I possibly be faltering? My aim here is to establish a fundamental plugin alongside its tests. Any guidance or insights on what might be going wrong would be immensely valuable.