From 04c3d71f5377622b3f153a7afab1b64efb25d504 Mon Sep 17 00:00:00 2001 From: Debora Crescenzo Date: Tue, 27 Jan 2026 10:49:29 +0000 Subject: [PATCH] MT#64314 Fix jest tests * Add testEnvironment: 'jsdom' to provide browser-like globals (DOM APIs) that Vue and test-utils need * Add explicit module path mapping in jest.config.js to force Jest to use the CommonJS bundle instead of the browser bundle. Change-Id: I659b122ed3884c229b5f6dab1f08e135bcb8c03d --- jest.config.js | 2 ++ test/jest/jest.setup.js | 3 +++ 2 files changed, 5 insertions(+) diff --git a/jest.config.js b/jest.config.js index dc3089b7..99849885 100755 --- a/jest.config.js +++ b/jest.config.js @@ -1,6 +1,7 @@ const esModules = ['quasar/lang', 'lodash-es', 'quasar'].join('|') module.exports = { + testEnvironment: 'jsdom', globals: { __DEV__: true }, @@ -41,6 +42,7 @@ module.exports = { ], moduleNameMapper: { '^vue$': 'vue', + '^@vue/test-utils$': '/node_modules/@vue/test-utils/dist/vue-test-utils.cjs.js', '^test-utils$': '@vue/test-utils', // '^quasar$': '/node_modules/quasar/dist/quasar.common.js', '^~/(.*)$': '/$1', diff --git a/test/jest/jest.setup.js b/test/jest/jest.setup.js index 3c7635a0..3ba9a3df 100755 --- a/test/jest/jest.setup.js +++ b/test/jest/jest.setup.js @@ -2,6 +2,9 @@ // console.log = jest.fn(() => { throw new Error('Do not use console.log() in production') }) jest.setTimeout(1000) +// Make Vue available globally for @vue/test-utils +global.Vue = require('vue') + // jest speedup when errors are part of the game // Error.stackTraceLimit = 0