I created a Vue plugin to activate console.logs if a user sets a property in localStorage. The plugin is a wrapper around console.log(). If the user enters 'localStorage.isLoggingData = true', then the plugin will test if that property exists in local storage and the logData function with run
index.js
import logData from '../plugins/logData
// I want to console.log this inital data coming into the app
async init ({ state, commit, dispatch }) {
try {
const { data } = await messaging.send(ACTION.READY)
logData(data)
main.js
import logData from '../plugins/logData
// Use logData to optionally view console.log statements
Vue.use(logData)
logData.js
export default {
install: function (Vue) {
Vue.prototype.$logData = function (dataToLog) {
const isLoggingData = localStorage.getItem('isLoggingData')
if (isLoggingData) {
console.log(dataToLog)
}
}
}
}
Currently when we have an application error we route to an error page, when I comment out the 'logData(data)' I am routed to the correct page in my app. Am I not creating the plugin or importing it correctly?
Updateindex.spec.js
import logData from '../plugins/logger'
import { createLocalVue, shallowMount } from '@vue/test-utils'
import App from '@src/App'
const localVue = createLocalVue()
localVue.use(Vuex)
localVue.use(logData)
const mocks = {
_vm: {}
}
mocks._vm.$logData = logData
const wrapper = shallowMount(App, {
mocks,
localVue
})
I am now told to mock _vm. Is this the correct way to mock it?