No More Posting New Topics!

If you have a question or an issue, please start a thread in our Github Discussions Forum.
This forum is closed for new threads/ topics.

Navigation

    Quasar Framework

    • Login
    • Search
    • Categories
    • Recent
    • Tags
    • Popular
    • Users
    • Groups
    • Search
    1. Home
    2. comteharbour
    3. Topics
    C
    • Profile
    • Following 0
    • Followers 0
    • Topics 3
    • Posts 6
    • Best 1
    • Groups 0

    Topics created by comteharbour

    • C

      @quasar/testing (jest) components not registered when VueRouter not created
      [v1] App Extensions • • comteharbour

      3
      0
      Votes
      3
      Posts
      637
      Views

      A

      Hi, new to unit test so I lack some experience, I’m also struggling with router/q-page unit test, but seems I am able to not come across your problem, hoping will help.
      I set up the test starting from quasar doc for Jtest, so I have my "test\jest_tests_\App.spec where, this is the code ( I’ve deleted some test automatically generated by quasar cli );
      It seems I overcome your problem, still I’ve problems because using the real router instead a mock, router.js import fails because of the base dir.
      I’m look over it trying finding out how solve this problem.

      ==================
      App.spec.js

      import { mount, createLocalVue, shallowMount } from ‘@vue/test-utils’
      import QBUTTON from ‘./demo/QBtn-demo.vue’
      import * as All from ‘quasar’
      import VueRouter from ‘vue-router’
      import mypage from ‘…/…/…/src/pages/MyPage.vue’
      import routes from ‘…/…/…/src/router/routes.js’
      import App from ‘…/…/…/src/App.vue’
      // import langEn from ‘quasar/lang/en-us’ // change to any language you wish! => this breaks wallaby 😞
      const { Quasar } = All

      const components = Object.keys(All).reduce((object, key) => {
      const val = All[key]
      if (val && val.component && val.component.name != null) {
      object[key] = val
      }
      return object
      }, {})

      describe(‘Mount Quasar’, () => {
      const localVue = createLocalVue()
      localVue.use(Quasar, { components }) // , lang: langEn
      localVue.use(VueRouter)

      const wrapper = mount(QBUTTON, {
      localVue
      })
      const vm = wrapper.vm

      […]

      it(‘render MyPage via ruting’, () => {
      const router = new VueRouter({ routes })
      const wrapper = mount( App, { localVue, router })
      router.push(’/mypage’)
      expect(wrapper.findComponent(mypage).exists()).toBe(true)
      })
      })

      ====================
      router.js

      const routes = [
      {
      path: ‘/’,
      component: () => import(‘layouts/MainLayout.vue’),
      children: [
      { path: ‘’, component: () => import(‘pages/Index.vue’) },
      {
      path: ‘/mypage’,
      component: () => import(‘pages/MyPage.vue’)
      }
      ]
      },

      // Always leave this as last one,
      // but you can also remove it
      {
      path: ‘*’,
      component: () => import(‘pages/Error404.vue’)
      }
      ]

      export default routes

    • C

      @quasar/testing: [Vue warn]: Error in render: "TypeError: Cannot read property 'lang' of undefined"
      [v1] App Extensions • • comteharbour

      9
      0
      Votes
      9
      Posts
      5096
      Views

      G

      You don’t have to mount Quasar globally. This also works:

      const localVue = createLocalVue() const wrapper = shallowMount( Component, //- pass the context to shallowMount, //- this will ensure that the wrapper refers to //- the instantiated localVue, //- and thus that `this.$q` is available { localVue } )
    • C

      [Solved] Using router from vuex action
      Framework • • comteharbour

      5
      0
      Votes
      5
      Posts
      6433
      Views

      C

      @rstoenescu It works. Thanks a lot !