Description
Subject of the issue
There is an infinite loop in the vue-test-utils error handler when using createLocalVue
more than once. Everything works correctly for the first test, but subsequent tests that use their own local vue instance will cause massive noise in the console
I have tested this with version 1.1.2
Steps to reproduce
- Create a component with an uncaught error
- Mount the component using a distinct local vue in beforeEach (createLocalVue)
- Have more than one test
Expected behaviour
Each test should run, and produce only the errors triggered by the code
Actual behaviour
You should see an error similar to this in the console:
console.error node_modules/vue/dist/vue.runtime.common.dev.js:621
[Vue warn]: Error in config.errorHandler: "RangeError: Maximum call stack size exceeded"
console.error node_modules/vue/dist/vue.runtime.common.dev.js:1884
RangeError: Maximum call stack size exceeded
at Array.push (<anonymous>)
at getParent (...\node_modules\@vue\test-utils\dist\vue-test-utils.js:2799:17)
at findAllParentInstances (...\node_modules\@vue\test-utils\dist\vue-test-utils.js:2805:3)
at errorHandler (...\node_modules\@vue\test-utils\dist\vue-test-utils.js:2912:32)
at ...\node_modules\@vue\test-utils\dist\vue-test-utils.js:2929:5
at Array.forEach (<anonymous>)
at errorHandler (...\node_modules\@vue\test-utils\dist\vue-test-utils.js:2928:26)
at ...\node_modules\@vue\test-utils\dist\vue-test-utils.js:2929:5
at Array.forEach (<anonymous>)
at errorHandler (...\node_modules\@vue\test-utils\dist\vue-test-utils.js:2928:26)
at ...\node_modules\@vue\test-utils\dist\vue-test-utils.js:2929:5
(...)
Possible Solution
After debugging the code, it is apparent that the first call to createLocalVue() does not have an errorHandler set. Subsequent calls, however, have their error handler set to the one in vue-test-utils. Whenever the child component has an uncaught error, it will call the vue-test-utils handler, which will call the parent's (our local vue) handler. Since it is the same handler, with the same arguments, there is infinite recursion
There are many possible solutions, but a workaround is to simply pass an empty errorHandler function:
createLocalVue({ errorHandler: () => {}})