Skip to content

Vuejs + Jest : “SyntaxError: Unexpected token <” #185

@JawedHook

Description

@JawedHook

I have a Vue file which imports a Vue file from node_modules. This file seems to not be recognize as a vue file when imported and doesn't use vue-jest.

I tried to use an htmlLoader, but doesn't work either.

Here is the error I get :

path/node_modules/vue-loading-spinner/src/components/Jumper.vue:1
({"Object.<anonymous>":function(module,exports,require,__dirname,__filename,global,jest){<template>                 
SyntaxError: Unexpected token <

Here is my jest.conf.js :

const path = require('path')

module.exports = {
  rootDir: path.resolve(__dirname, '../../'),
  moduleFileExtensions: [
    'js',
    'vue',
    'html'
  ],
  moduleNameMapper: {
    '^@/(.*)$': '<rootDir>/src/$1',
  },
  transform: {
    '^.+\\.js$': '<rootDir>/node_modules/babel-jest',
    '.*\\.vue$': '<rootDir>/node_modules/vue-jest',
    "^.+\\.html$": "<rootDir>/test/utils/htmlLoader.js"
  },
  testPathIgnorePatterns: [
    "<rootDir>/node_modules/"
  ],
  modulePaths: [
    "<rootDir>"
  ],
  setupFiles: ['<rootDir>/test/unit/setup'],
  testMatch: [
    '<rootDir>/(test/unit/**/*.spec.(js|jsx|ts|tsx)|**/__tests__/*.(js|jsx|ts|tsx))'
  ]
}

And here is my test file ( I know there is no test in this file, but not necessary at the moment if I can mount my component ) :

import { shallowMount } from "@vue/test-utils"
import Card from '@/components/Card'
import { propsSet } from '../../datas/components/Card'
import Brace from 'vue-bulma-brace'

describe('FreeSql Unit Tests', () => {
    test('FreeSql : Display correct', () => {
        
        const wrapper = shallowMount(FreeSql, {
            propsData:{
                ...propsSet
            },
            stubs:{
                Brace
            }
        })
    })
})

Thanks for your help.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions