Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

886
Visualizações
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 Respostas
Responde à pergunta

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 Relatório
Responde à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda