Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Tagged template strings are not supported #98

Closed
mjss opened this issue Aug 10, 2018 · 5 comments · Fixed by #288
Closed

Tagged template strings are not supported #98

mjss opened this issue Aug 10, 2018 · 5 comments · Fixed by #288

Comments

@mjss
Copy link

mjss commented Aug 10, 2018

If tagged template strings are used, test suit will fail with following error:

Tagged template strings are not supported. Use `transforms: { templateString: false }` to skip transformation and disable this error, or `transforms: { dangerousTaggedTemplateString: true }` if you know what you're doing (1:303)

      at Node.initialise (node_modules/vue-template-es2015-compiler/buble.js:12998:10)
          at Array.forEach (<anonymous>)
          at Array.forEach (<anonymous>)

Apparently, this error message is from buble.js.
It seems that vue-jest uses vue-template-es2015-compiler, and vue-template-es2015-compiler uses buble.
But neither vue-jest nor vue-template-es2015-compiler explains whether it is necessary and how to configure buble.

Is it possible to resolve this in vue-jest?
Any fixes or explanations are appreciated. Thank you.

I created a sample project to illustrate the issue. Steps to reproduce:

  1. clone https://github.com/mjss/vue-jest-with-tagged-template
  2. run npm test:unit
@danrocha
Copy link

@mjss did you manage to solve this somehow?
I am trying to test some components which use tagged template strings and I am having these errors with Jest:

Tagged template strings are not supported. Use `transforms: { templateString: false }` to skip transformation and disable this error, or `transforms: { dangerousTaggedTemplateString: true }` if you know what you're doing

The error is coming from an <apollo-query> component with a gql string.

@mjss
Copy link
Author

mjss commented Jun 11, 2019

@danrocha No I didn't resolve this issue back then. I am not sure whether the newer versions of vue-jest or vue-template-es2015-compiler supports tagged template strings now. Tagged template strings were not a must-have in our project, thus we just removed them.

@axwalker
Copy link

@danrocha I'm in the same boat as you - trying to test components that use <apollo-query> + gql - did you find a solution in the end?

@danrocha
Copy link

No, I gave up on the apollo components a while ago!

@FRSgit
Copy link

FRSgit commented Sep 28, 2020

Hey, I've added a fix (or rather - I've extended the vue-jest library to address this issue) and created a PR #288.

If you want to use it in your project where you have vue-jest as a direct dependency:

  • remove the package with npm uninstall vue-jest or yarn remove vue-jest,
  • add it back from my fork npm install --save-dev https://github.com/FRSource/vue-jest#feat-add-compile-template-options or yarn add -D https://github.com/FRSource/vue-jest#feat-add-compile-template-options.

Or if you're using vue-jest via @vue/cli-plugin-unit-jest:

  • add this to your package.json:
    "resolutions": {
      "**/vue-jest": "git+https://github.com/FRSource/vue-jest#feat-add-compile-template-options"
    }
    
  • run yarn install.

And ofc stay updated on when the #288 would get merged into the master to switch back to the official vue-jest package!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging a pull request may close this issue.

5 participants