Empresas
Empleos
  • Sobre nosotros
  • Soluciones
    • Publicación de vacantes
      Publica tu vacante y recibe candidatos calificados en 48h.
    • Evaluación de candidatos
      500+ pruebas técnicas y psicológicas, más anti-fraude.
    • Headhunting
      Búsqueda ejecutiva a la medida de principio a fin.
    • Nómina + EOR
      Dispersión de nómina y EOR en más de 15 países de LATAM.
  • Precios
  • Empleos

0

887
Vistas
JEST unit test script fails with TypeError: this._environment.runScript is not a function

I was assigned a task of setting up Jest unit testing for a Vue application. I had several attempts at accomplishing it and solved several issues on the way thanks to other questions here. However, now I'm stuck with the following error when I do npm run test:unit ("test:unit": "vue-cli-service test:unit"):

TypeError: this._environment.runScript is not a function

  at Runtime._execModule (node_modules/@vue/cli-plugin-unit-jest/node_modules/jest-runtime/build/index.js:856:41)

Following is the Jest config I added to the package.json:

"jest": {
    "testEnvironment": "jsdom",
    "preset": "ts-jest",
    "moduleNameMapper": {
      "\\.(css|less|sass|scss)$": "<rootDir>/tests/mocks/styleMock.js",
      "^@/(.*)$": "<rootDir>/src/$1"
    },
    "transform": {
      "<rootDir>/src/data/.+\\.(j|t)sx?$": "ts-jest",
      ".*\\.(vue)$": "vue-jest",
      ".*\\.(js)$": "babel-jest"
    },
    "transformIgnorePatterns": [
      "/node_modules/(?!vuetify)",
      "<rootDir>/src/(?!data/.*)"
    ],
    "testPathIgnorePatterns": [
      "/node_modules/(?!vuetify)"
    ]
  }

Originally, I had 'node' for testEnvironment. But I've gotten the this._environment.runScript is not a function error for the first time. I've read that I could use 'jsdom' instead. For that I updated babel.config.js:

module.exports = {
   env: {
     test: {
       presets: [['env', { targets: { node: 'current' } }]],
       plugins: ['@babel/plugin-transform-modules-commonjs'],
     },
   },
}

But this resulted in the error saying that babel-preset-env module is missing. As I understood, the module is not a stand-alone module anymore. So, I changed babel.config.js:

module.exports = {
  presets: [
    [
      '@babel/preset-env',
      {
        modules: 'commonjs',
        targets: {
          node: 'current',
        },
      },
    ],
  ],
}

And now I'm back to TypeError: this._environment.runScript is not a function. Has anyone encountered a similar problem? Would appreciate your help.

about 4 years ago · Juan Pablo Isaza
1 Respuestas
Responde la pregunta

0

Upgrading Jest from ^24 to ^27 fixed it for me. Now my tests are running again.

I upgraded Nodejs some days ago, maybe this caused the issue.

about 4 years ago · Juan Pablo Isaza Denunciar
Responde la pregunta
Encuentra empleos remotos

¡Descubre la nueva forma de encontrar empleo!

Top de empleos
Top categorías de empleo
Empresas
Publicar vacante Precios Comercial
Legal
Términos y condiciones Política de privacidad
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomiéndame algunas ofertas
Necesito ayuda