Catch Vue.js warnings for unit testing required properties
Unfortunately it looks like the only way to do this is to hook into the Vue.warnHandler
I used a variable and reset it on the afterEach
hook (Mocha) like so:
let localVue;let hasWarning = false;function functionToWrapShallowMount(propsData) { const Wrapper = shallowMount(Control, { propsData, provide: { $validator: () => {} }, localVue }); return Wrapper;}before(() => { localVue = createLocalVue(); Vue.config.warnHandler = () => { hasWarning = true; };});afterEach(() => { hasWarning = false;});it('throws a warning', () => { const { vm } = functionToWrapShallowMount({ name: 'foooo', value: 'bad' }); vm.name.should.eq('foooo'); hasWarning.should.eq(true);});
The catch to this is you cannot use the localVue
from Vue test utils you must use the Vue
instance imported from vue
.