vue-test-utils: Not working in Browser
Wanted to use this in browser testing using Mocha, chai, sinon, expect… but it seems like this is only meant to be used in Node or at least after building it. I did that using browserify, but it is throwing this error:
VM1397:27 [Vue warn]: You are using the runtime-only build of Vue where the template compiler is not available. Either pre-compile the templates into render functions, or use the compiler-included build.
This implies that I have to change it’s source for it work properly for my case, which is something I think shouldn’t happen. I thought maybe I am missing something or maybe that scenario wasn’t thought through enough.
Is there a clear proper way of using these utilities in the browser without any complicated setup processes. Simply getting the script using the script tag and start using it right away.
About this issue
- Original URL
- State: closed
- Created 7 years ago
- Comments: 16 (7 by maintainers)
seems like the variable
vueTemplateCompileris a different variable from whatVueTemplateCompileris exposing in the browser version, note the capital letter ‘V’. either fix that in vue-test-utils or in vue-template-compiler.i suggest fix to be done here in vue-test-utils: every instance of
vueTemplateCompilerto be changed toVueTemplateCompilerandvueTestUtilstoVueTestUtils.VueTemplateCompilervar should also be attached towindowin addition toglobal. Again, in the iife file,vueTestUtilsvar should be attached toglobalandwindowThis helps when using jspm, systemjs etc. Just importing or script tagging these files should be enough to expose those modules to the window and global object and with their correct types;
VueTemplateCompilerandVueTestUtilsIt’s set as a peer dependency in the commonjs build, so users can use the version they’ve installed. In the AMD and UMD version, it needs to be passed as a dependency. So in those builds, the user is required to supply Vue themselves.
Yes, that’s a good idea 🙂. With a runtime build, it will work how you described. The user will be able to add Vue and Vue Template Compiler as global variables, and the runtime build will use them