Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

476
Views
Using Jest moduleNameMapper without typescript?

i got the current jest config setup as the following:

module.exports = {
  testEnvironment: 'jsdom',
  transform: {
    '^.+\\.vue$': '@vue/vue3-jest',
    '^.+\\js$': 'babel-jest'
  },
  testRegex: '(/__tests__/.*|(\\.|/)(test|spec))\\.(js)$',
  moduleFileExtensions: ['vue', 'js'],
  transformIgnorePatterns: ['/node_modules/(?!@ionic/vue|@ionic/vue-router|@ionic/core|@stencil/core|ionicons)']
}

However this cause an issue when adding a simple vue test:

import { mount } from '@vue/test-utils'
import HomePage from '@/views/HomePage.vue'

describe('HomePage.vue', () => {
  it('renders home vue', () => {
    const wrapper = mount(HomePage)
    expect(wrapper.text()).toMatch('Ready to create an app?')
  })
})

The @ symbol isn't resolved as wanted:

  ● Test suite failed to run

    Cannot find module '@/views/HomePage.vue' from 'tests/unit/example.spec.js'

      1 | import { mount } from '@vue/test-utils'
    > 2 | import HomePage from '@/views/HomePage.vue'
        | ^
      3 |
      4 | describe('HomePage.vue', () => {
      5 |   it('renders home vue', () => {

      at Resolver.resolveModule (node_modules/jest-resolve/build/resolver.js:324:11)
      at Object.<anonymous> (tests/unit/example.spec.js:2:1)

However, adding

  moduleNameMapper: {
    '^@/(.*)$': '<rootDir>/src/$1',
  },

within the jest.config.js file give me this error:

  ● Test suite failed to run

    Cannot find module 'ts-jest/dist/config/config-set'

Installing ts-jest & typescript would work, but is there any way to fix this issue without having to deal with typescript?

about 4 years ago · Juan Pablo Isaza
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!