Use 3rd party UI libs in tests #384
Replies: 3 comments 11 replies
-
Hi! I think the initialization is fine. This is probably due to your Jest config not being able to parse/understand CSS or aliases? |
Beta Was this translation helpful? Give feedback.
-
Iam having the same issue here. Withouth passing Quasar as plugin, my tests will fail because of some dependency error for which quasar is needed. So that install function wants to set Can anyone maybe suggest a workaround or a solution to this? im also really stuck here |
Beta Was this translation helpful? Give feedback.
-
I have running tests with Quasar but I use stubbed quasar components or shallow mount most of the time because this makes it alot easier rather than completely render the quasar components with dependencies. In case you still want to completely render the quasar components, this was my code: // jest.config.js
const esModules = ['quasar/lang', 'quasar/dist/quasar.esm.prod.js'].join('|')
module.exports = {
// ...
transformIgnorePatterns: [`node_modules/(?!(${esModules}))`],
// ...
} // HelloWorld.spec.js
import { mount } from '@vue/test-utils'
import HelloWorld from '@/components/HelloWorld.vue'
import { Quasar } from 'quasar/dist/quasar.esm.prod'
// Optionally options for quasar
const quasarOptions = {}
describe('HelloWorld.vue', () => {
it('renders HelloWorld', () => {
// Manually reset Quasars internal install flag
Quasar.__qInstalled = undefined
const wrapper = mount(HelloWorld, {
global: {
plugins: [[Quasar, quasarOptions]]
}
})
expect(wrapper.exists()).toBe(true)
})
}) I haven't test this snippet, maybe I missed something. |
Beta Was this translation helpful? Give feedback.
-
Hi,
I am trying to run a test for component that uses third party UI library - quasar (vue-cli version).
If I just mount the component, the test will run but it will output a warning that some components are not found (quasar not initiated in the test).
If I try to add Quasar to mount as global:
const wrapper = mount(HelloWorld, { global: { plugins: [q] }, })
the test is not even started and jest is complaining about transformer (probably can't handle
@
in css imports):`
C:....\test-utils-playground\node_modules@quasar\extras\roboto-font\roboto-font.css:1
({"Object.":function(module,exports,require,__dirname,__filename,global,jest){@font-face {
^
`
This is how quasar is initialised in
main.js
:createApp(App) .use(Quasar, quasarUserOptions) .use(store) .use(router) .mount('#app')
What is the correct way to initialise 3rd party library in mount (or outside - globally) as the createLocalVue is no longer available in next iteration of vue-test-utils, please?
--- EDIT ---
I understand the css import issues related to jest. I managed them with moduleNameMapper. However, the initialisation part is still failing.
When I don't import Quasar in plugins, VTU will warn about "Failed to resolve component: ".
When I do import Quasar in plugins:
I am getting errors about
$q
undefined:This is how quasar is initialised in main.js:
Both the quasar instance and quasarUserOptions are passed as one plugin.
How can I pass both to
global.plugins
in VTU?Is this the correct way to mount third party libraries?
Beta Was this translation helpful? Give feedback.
All reactions