quasar-testing icon indicating copy to clipboard operation
quasar-testing copied to clipboard

Qv1 - Quasar Portal based components and localVue issues

Open AlexanderKuzmichev opened this issue 4 years ago • 2 comments

There is a problem with testing components based on Quasar Portal with localVue (a Vue instance created by createLocalVue() method). The problem is that all plugins we install for localVue (e.g. vuex or vue-router) are added to the root Vue instance created by mount but aren't added to the Vue instance created by Quasar Portal. So they are missed for all components inside the Quasar Portal based components. @IlCallo fyi

AlexanderKuzmichev avatar Feb 10 '21 18:02 AlexanderKuzmichev

Same issue here. I believe the cases in Mocking notify plugin in a test and Issue #49 are of the same reason.

A temporary workaround could be simply mocking the components based on Quasar Portal so that they cannot access $q, thus eliminating the warnings. Take Notify as an example:

import {
  mountFactory,
  qLayoutInjections
} from '@quasar/quasar-app-extension-testing-unit-jest'
// ...
import Router from 'src/router'
import Store from 'src/store'
import {
  // ...,
  Notify
} from 'quasar'
import Login from 'pages/Login.vue'

Notify.create = jest.fn()

const factory = mountFactory(Login, {
  mount: {
    router: Router,
    store: Store,
    provide: qLayoutInjections(),
    mocks: { Notify }
  },
  // ...
})

SignorMercurio avatar Mar 31 '21 19:03 SignorMercurio

If anyone wants to dig deeper on this one, please do! I can provide guidance if needed, but won't be able to come back on these kind of issues for some time, as we prepare for Qv2 migration

IlCallo avatar Apr 01 '21 10:04 IlCallo

Closing this as not relevant anymore, please upgrade to Qv2 and use the new Jest AE beta version

IlCallo avatar Feb 28 '23 14:02 IlCallo