link2740 link2741 link2742 link2743 link2744 link2745 link2746 link2747 link2748 link2749 link2750 link2751 link2752 link2753 link2754 link2755 link2756 link2757 link2758 link2759 link2760 link2761 link2762 link2763 link2764 link2765 link2766 link2767 link2768 link2769 link2770 link2771 link2772 link2773 link2774 link2775 link2776 link2777 link2778 link2779 link2780 link2781 link2782 link2783 link2784 link2785 link2786 link2787 link2788 link2789 link2790 link2791 link2792 link2793 link2794 link2795 link2796 link2797 link2798 link2799 link2800 link2801 link2802 link2803 link2804 link2805 link2806 link2807 link2808 link2809 link2810 link2811 link2812 link2813 link2814 link2815 link2816 link2817 link2818 link2819 link2820 link2821 link2822 link2823 link2824 link2825 link2826 link2827 link2828 link2829 link2830 link2831 link2832 link2833 link2834 link2835 link2836 link2837 link2838 link2839 link2840 link2841 link2842 link2843 link2844 link2845 link2846 link2847 link2848 link2849 link2850 link2851 link2852 link2853 link2854 link2855 link2856 link2857 link2858 link2859 link2860 link2861 link2862 link2863 link2864 link2865 link2866 link2867 link2868 link2869 link2870 link2871 link2872 link2873 link2874 link2875 link2876

[Vue.js] Cannot test Vue component with Jest Syntax error - Unexpected identifier

Project is created with @vue/cli@3.6.3. This is package.json

“scripts”: {
“serve”: “vue-cli-service serve”,
“build”: “vue-cli-service build”,
“lint”: “vue-cli-service lint”,
“test”: “npm run lint && npm run test:unit”,
“test:unit”: “jest –no-cache”
“dependencies”: {
“core-js”: “^2.6.5”,
“vue”: “^2.6.10”
“devDependencies”: {
“@vue/cli-plugin-babel”: “^3.6.0”,
“@vue/cli-plugin-eslint”: “^3.6.0”,
“@vue/cli-service”: “^3.6.0”,
“@vue/eslint-config-standard”: “^4.0.0”,
“babel-eslint”: “^10.0.1”,
“babel-jest”: “^24.7.1”,
“eslint”: “^5.16.0”,
“eslint-plugin-vue”: “^5.0.0”,
“jest”: “^24.7.1”,
“vue-jest”: “^3.0.4”,
“vue-template-compiler”: “^2.5.21”
“jest”: {
“transform”: {
“^.+\\.js$”: “babel-jest”,
“^.+\\.vue$”: “vue-jest”

This is my test

import Item from ‘../Item.vue’

describe(‘Item.vue’, () => {
test(‘sanity test’, () => {

with the component Item.vue.js being


and this is the result

I get the error on the import statement. I thought this would be dealt by using the jest transformers, but it is not. What else do i need to add to pass the tests? The project url is this.

Solution :

You’ve never defined any Item component.
The only file you have in the project is Item.vue.js which contains only a template, there is no way for vuejs to import ‘Item’ since you’ve never declared the template as ‘Item’.

You should have a look to the VueJS Documentation about components ! In the first example you can see how the binding classname-template is done.

Then you will be able to import ‘Item’ from Item.vue.