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

889
Views
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 answers
Answer question

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 Report
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!