"Cannot convert undefined or null to object" at installQuasar
See original GitHub issueApplication uses vue3 + ts + quasar and jest for testing. Getting error “Cannot convert undefined or null to object” at installQuasar when doing localVue.use(Quasar) or plugins: [Quasar] in test file. The config files are as mentioned below
package.json -
"dependencies": {
"@quasar/extras": "^1.11.4",
"@types/vue-i18n": "^7.0.0",
"axios": "^0.20.0",
"core-js": "^3.6.5",
"d3": "^6.2.0",
"echarts": "^5.1.2",
"lodash": "~4.17.20",
"qs": "^6.9.6",
"quasar": "^2.2.1",
"rison": "^0.1.1",
"vue": "3.0.6",
"vue-i18n": "^9.1.5",
"vue-router": "^4.0.12"
},
"devDependencies": {
"@types/d3": "^5.16.3",
"@types/echarts": "^4.9.8",
"@types/lodash": "^4.14.160",
"@types/node": "^14.17.32",
"@types/rison": "0.0.6",
"@types/webpack-env": "^1.16.3",
"@typescript-eslint/eslint-plugin": "^5.3.1",
"@typescript-eslint/parser": "^5.3.1",
"@vue/cli-plugin-babel": "^4.5.14",
"@vue/cli-plugin-eslint": "^4.5.14",
"@vue/cli-plugin-router": "^4.5.14",
"@vue/cli-plugin-typescript": "^4.5.14",
"@vue/cli-plugin-unit-jest": "^4.5.15",
"@vue/cli-service": "~4.5.0",
"@vue/compiler-sfc": "3.0.0",
"@vue/eslint-config-prettier": "^6.0.0",
"@vue/eslint-config-typescript": "^9.0.1",
"@vue/test-utils": "^2.0.0-0",
"babel-core": "^7.0.0-bridge.0",
"babel-plugin-transform-imports": "2.0.0",
"eslint": "^7.0.0",
"eslint-plugin-prettier": "^3.1.3",
"eslint-plugin-vue": "^7.0.0",
"node-sass": "4.13.0",
"prettier": "^1.19.1",
"sass-loader": "^8.0.2",
"typescript": "~3.9.3",
"vue-cli-plugin-quasar": "~4.0.4",
"vue-jest": "^5.0.0-0"
}
jest.config.js -
module.exports = {
preset: "@vue/cli-plugin-unit-jest/presets/typescript-and-babel",
transformIgnorePatterns: ["node_modules/(?!(quasar|echarts|zrender)/)"],
transform: {
// process *.vue files with vue-jest
'^.+\\.vue$': require.resolve('vue-jest'),
}
};
babel.config.js -
module.exports = {
presets: ["@vue/cli-plugin-babel/preset"]
};
test file assets.spec.ts-
import { Quasar } from "quasar";
import { createApp } from "vue";
const localVue = createApp({});
localVue.use(Quasar);
Error
Test suite failed to run
TypeError: Cannot convert undefined or null to object
at Function.assign (<anonymous>)
4 |
5 | const localVue = createApp({});
> 6 | localVue.use(Quasar);
| ^
7 |
at installQuasar (node_modules/quasar/dist/quasar.cjs.prod.js:6:13539)
at Object.install (node_modules/quasar/dist/quasar.cjs.prod.js:6:468377)
at Object.use (node_modules/@vue/runtime-core/dist/runtime-core.cjs.js:2962:28)
at Object.<anonymous> (tests/unit/assets.spec.ts:6:10)
Issue Analytics
- State:
- Created 2 years ago
- Comments:8 (4 by maintainers)
Top Results From Across the Web
Getting an error “Cannot convert undefined or null to object ...
The better answer because the typeof solves the problem of the data being "truthy" but not an object, in one go. In TypeScript...
Read more >jest typeerror: cannot convert undefined or null to object
From the command line npm run test results in the error: TypeError: Cannot convert undefined or null to object at Function.keys () at...
Read more >Cannot convert undefined or null to object - YouTube
JavaScript : How to resolve TypeError: Cannot convert undefined or null to object [ Gift : Animated Search Engine ...
Read more >Configuring quasar.config.js
You'll notice that /quasar.config.js exports a function that takes a ctx (context) parameter and returns an Object. This allows you to dynamically change ......
Read more >Cannot convert undefined or null to object : r/learnjavascript
For some reason, when I fetch data and console.log it, it displays the data. But when I set it to a state, it...
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
Here is a solution that is based on a Vite setup: https://github.com/quasarframework/quasar/discussions/12177#discussioncomment-2046577.
I am hoping to create an example repo and write a tutorial/article about Vue CLI and Vite setups.
Correct, CJS exported version is optimized for SSR, so it will give you all kind of weird issues while testing You need to add these lines to your jest config to use and transform the ESM build version:
Also take a look to https://github.com/quasarframework/quasar-testing/blob/5a761b2d8f25656d09d237a525e96cf60e5401ae/packages/unit-jest/src/helpers/install-quasar-plugin.ts#L6 implementation and usage, as Yusuf correctly pointed out.