question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Jest tests fail to run from project created through vue-cli

See original GitHub issue

Version

3.0.0-beta.11

Reproduction link

https://cl.ly/rsUF

Steps to reproduce

Following the guide here: https://vuejs-templates.github.io/webpack/ Select the following options during setup config:

  • Vue Build: Runtime Compiler
  • Install vue-router? No
  • Use ESLint to lint your code? Yes
  • Pick an ESLint preset: Standard
  • Set up unit tests: Yes
  • Pick a test runner: jest
  • Setup e2e tests with Nightwatch? No
  • Should we run npm install for you after the project has been created? yarn

What is expected?

The HelloWorld.spec.js test will run and pass.

What is actually happening?

Test suite failed to run

my-path/my-project/test/unit/setup.js:1
({"Object.<anonymous>":function(module,exports,require,__dirname,__filename,global,jest){import Vue from 'vue';
                                                                                         ^^^^^^

SyntaxError: Unexpected token import

Issue Analytics

  • State:closed
  • Created 5 years ago
  • Comments:9 (1 by maintainers)

github_iconTop GitHub Comments

2reactions
rgalaxycommented, Oct 22, 2018

Is there any possibilities this is fixable? it ried to clearCache but it still not working. do i need to add something on my babelrc? i havent touch anything about test and when i tried to create a test on my service and run it, it show this error. i tried to install this and that but it just introduce another series of chaining errors. this is the error when i run test ` FAIL /tests/myService.spec.js ● Test suite failed to run

Jest encountered an unexpected token

This usually means that you are trying to import a file which Jest cannot parse, e.g. it's not plain JavaScript.

By default, if Jest sees a Babel config, it will use that to transform your files, ignoring "node_modules".

Here's what you can do:
 • To have some of your "node_modules" files transformed, you can specify a custom "transformIgnorePatterns" in your config.
 • If you need a custom transformation specify a "transform" option in your config.
 • If you simply want to mock your non-JS modules (e.g. binary assets) you can stub them out with the "moduleNameMapper" config option.

You'll find more details and examples of these config options in the docs:
https://jestjs.io/docs/en/configuration.html

Details:

C:\*\*\*\*\*\myService.spec.js:1
({"Object.<anonymous>":function(module,exports,require,__dirname,__filename,global,jest){import "core-js/modules/es6.array.iterator";
                                                                                         ^^^^^^

SyntaxError: Unexpected token import

  at ScriptTransformer._transformAndBuildScript (node_modules/jest-runtime/build/script_transformer.js:403:17)

`

2reactions
brandonaaskovcommented, Jun 12, 2018

@judgeyboy I’m getting basically the same problem when I run tests as well. It seems like it’s something with the webpack template, so I opened an issue there: https://github.com/vuejs-templates/webpack/issues/1404

I haven’t had time to dig into it yet, but at least there’s an issue open for now.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Cannot run Jest unit tests with @vue/cli-service : WEB-34734
The test as scaffolded by Vue CLI, works. You know this by running npm run test:unit - you'll see the test passes just...
Read more >
Error in unit test a Vue 2 project to Vue 3 (vue-cli)
I get this error from running the base HelloWorld component that comes from the project scaffold. My dependencies are the following: " ...
Read more >
vue/cli-plugin-unit-jest
Debugging Tests​​ Note that directly running jest will fail because the Babel preset requires hints to make your code work in Node. js,...
Read more >
Vue.js 3 Unit Testing Setup & Basics Tutorial - KoderHQ
Lesson Project · Jest is the framework used to perform unit testing. · Vue CLI Unit Jest Plugin installs and configures the necessary...
Read more >
Setting up for TDD - Vue Testing Handbook
Create a new project by running vue create [project-name] . Choose "Manually select features" and "Unit Testing", and "Jest" for the test runner ......
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found