Example project using TypeScript, Jest + vue-test-utils together
by vuejsVue
Last 12 weeks · 0 commits
1 of 6 standards met
Repository: vuejs/vue-test-utils-typescript-example. Description: Example project using TypeScript, Jest + vue-test-utils together Stars: 62, Forks: 28. Primary language: Vue. Languages: Vue (60.8%), HTML (15.6%), TypeScript (13%), JavaScript (10.6%). Open PRs: 1, open issues: 2. Last activity: 6y ago. Community health: 25%. Top contributors: eddyerburgh.
I faced the same issue in my project and tried this one as a reference. Surprisingly, this reference project produced the same error. I use updated packages in my projects, but error is the same. So, I cloned this repo, opened it in VS Code, then put in terminal: Here is the result: Executing task: npm run test > vue-test-utils-typescript-example@0.1.0 test d:\Projects\vue-test-utils-typescript-example npm run test:unit vue-test-utils-typescript-example@0.1.0 test:unit d:\Projects\vue-test-utils-typescript-example jest FAIL src/components/__tests__/HelloWorld.spec.ts ● 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: D:\Projects\vue-test-utils-typescript-example\src\components\__tests__\HelloWorld.spec.ts:1 ({"Object.":function(module,exports,require,__dirname,__filename,global,jest){import 'jest'; ^^^^^^ SyntaxError: Unexpected token import at ScriptTransformer._transformAndBuildScript (node_modules/jest/node_modules/jest-cli/node_modules/jest-runtime/build/script_transformer.js:403:17) Test Suites: 1 failed, 1 total Tests: 0 total Snapshots: 0 total Time: 1.551s Ran all test suites. npm ERR! code ELIFECYCLE npm ERR! errno 1 npm ERR! vue-test-utils-typescript-example@0.1.0 test:unit: npm ERR! Exit status 1 npm ERR! npm ERR! Failed at the vue-test-utils-typescript-example@0.1.0 test:unit script. npm ERR! This is probably not a problem with npm. There is likely additional logging output above. npm ERR! A complete log of this run can be found in: npm ERR! C:\Users\LEVYAS.TRANSAS\AppData\Roaming\npm-cache\_logs\2019-11-20T08_35_07_810Z-debug.log npm ERR! code ELIFECYCLE npm ERR! errno 1 npm ERR! vue-test-utils-typescript-example@0.1.0 test: npm ERR! Exit status 1 npm ERR! npm ERR! Failed at the vue-test-utils-typescript-example@0.1.0 test script. npm ERR! This is probably not a problem with npm. There is likely additional logging output above. What could be the reason and how to fix it?** P.S. There is PR to this repo, I tried this one too and it doesn't produce that error. I tried to figure out the defining differences all the previous workday, but, unfortunately, with no success.
Hi, i a real-world scenario I have the following class in my vue file (adapted to the example provided in this project): My test is as follows: I have typed the as here because that works (i.e. does not give a red squiggly line in my editor), but the method returns a . Typing the wrapper as does not give me the benefits of code completion etc. As what type should I type the wrapper so that I can use the correct typing in the remainder of the test? I tried , , but nothing worked.