Vue CLI v4.5.13 ? Please pick a preset: Manually select features ? Check the features needed for your project: (*) Choose Vue version (*) Babel >(*) TypeScript ( ) Progressive Web App (PWA) Support ( ) Router ( ) Vuex ( ) CSS Pre-processors ( ) Linter / Formatter ( ) Unit Testing ( ) E2E Testing
Enterキーを押すとVue.jsのバージョン選択画面に。今回は3.xを選択します。
Vue CLI v4.5.13 ? Please pick a preset: Manually select features ? Check the features needed for your project: Choose Vue version, Babel, TS, Linter, Unit, E2E ? Choose a version of Vue.js that you want to start the project with (Use arrow keys) 2.x ❯ 3.x
その後、いくつか設定ありますが、好みで設定しましょう。(“?”のあとが今回選択したものです)
Vue CLI v4.5.13 ? Please pick a preset: Manually select features ? Check the features needed for your project: Choose Vue version, Babel, TS, Linter ? Choose a version of Vue.js that you want to start the project with 3.x ? Use class-style component syntax? No ? Use Babel alongside TypeScript (required for modern mode, auto-detected polyfills, transpiling JSX)? No ? Where do you prefer placing config for Babel, ESLint, etc.? In dedicated config files ? Save this as a preset for future projects? (y/N) No
test("increments value on click", async () => { // The render method returns a collection of utilities to query your component. const { getByText } = render(Counter);
// getByText returns the first matching node for the provided text, and // throws an error if no elements match or if more than one match is found. getByText("Times clicked: 0");
const button = getByText("increment");
// Dispatch a native click event to our button element. await fireEvent.click(button); await fireEvent.click(button);
FAIL src/tests/counter.test.ts ● Test suite failed to run
TypeError: Cannot destructure property 'config' of 'undefined' as it is undefined.
at Object.getCacheKey (node_modules/vue-jest/lib/index.js:10:7) at ScriptTransformer._getCacheKey (node_modules/@jest/transform/build/ScriptTransformer.js:280:41) at ScriptTransformer._getFileCachePath (node_modules/@jest/transform/build/ScriptTransformer.js:351:27) at ScriptTransformer.transformSource (node_modules/@jest/transform/build/ScriptTransformer.js:588:32) at ScriptTransformer._transformAndBuildScript (node_modules/@jest/transform/build/ScriptTransformer.js:758:40) at ScriptTransformer.transform (node_modules/@jest/transform/build/ScriptTransformer.js:815:19)
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: • If you are trying to use ECMAScript Modules, see https://jestjs.io/docs/en/ecmascript-modules for how to enable it. • 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:\Users\{UserName}\sample\src\components\Counter.vue:1 ({"Object.<anonymous>":function(module,exports,require,__dirname,__filename,global,jest){import { defineComponent } from "vue"; ^^^^^^
SyntaxError: Cannot use import statement outside a module
1 | import { render, fireEvent } from "@testing-library/vue"; > 2 | import Counter from "../components/Counter.vue"; | ^ 3 | 4 | test("increments value on click", async () => { 5 | // The render method returns a collection of utilities to query your component.
at Runtime.createScriptFromCode (node_modules/jest-runtime/build/index.js:1350:14) at Object.<anonymous> (src/tests/counter.test.ts:2:1)