After much Googling I'm coming up short on how to test a Vue plugin using Jest without getting the rather annoying warning log:
You are running Vue in development mode.
I've searched an searched on how to disable/mute/appease this and the only solution I have found that works is to set NODE_ENV
to "production" before running jest
:
"test": "cross-env NODE_ENV=production jest"
Since jest
sets NODE_ENV
to "test" by default, I'm not sure if this has any side effects or not?
Either way, it feels a little wrong to me.
As a really simple test case, let's say I have a plugin that looks like this:
// plugin.js
export default {
install(Vue, options) {
Vue.prototype.$upper = (text) => text.toUpperCase()
}
}
...then if I wanted to test this plugin, my test file might look something like this:
// plugin.spec.js
import Vue from 'vue'
import VueUpper from './plugin'
it('adds an $upper method to the Vue prototype', () => {
expect(Vue.prototype.$upper).toBeUndefined()
Vue.use(VueUpper)
expect(typeof Vue.prototype.$upper).toBe('function')
})
it('transforms a string to upper case', () => {
expect(Vue.prototype.$upper('foo')).toBe('FOO')
})
Any help would be very much appreciated!