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

Jest testing recipe

Open smajl opened this issue 5 years ago • 1 comments

Hi @NickHurst, please - by any chance - do you have an example how to make Jest unit tests seamlessly work with nuxt-quasar (Quasar 1.x)?

I followed recommendations in here: https://forum.quasar-framework.org/topic/1864/0-15-1-components-registering-within-jest-tests/22

// jest.config.js

module.exports = {
  moduleNameMapper: {
    ...
    'quasar': 'quasar/dist/quasar.umd.min.js',
  },
  ...
}

// Login.spec.ts

import 'jest'
import Quasar, * as All from 'quasar'
import { createLocalVue, shallowMount } from '@vue/test-utils'
import Login from '../Login.vue'

const localVue = createLocalVue()
localVue.use(Quasar, { components: All, directives: All, plugins: All })

describe('Login', () => {
  test('is a Vue instance', () => {
    const wrapper = shallowMount(Login, { localVue })
    expect(wrapper.isVueInstance()).toBeTruthy()
  })
})

This test now runs and passes, but I am wondering if there is a better way (if you are running tests on any of your nuxt-quasar project). Thanks in advance.

smajl avatar Jul 25 '19 10:07 smajl

I don't use Jest in any of my nuxt projects (I use AVA), so I don't currently have any recommendations. However, I'm currently working on creating the unit tests for the module itself, and am using Jest as it's more popular that AVA, so I'll look into finding any way to make testing a bit easier.

NickHurst avatar Jul 26 '19 15:07 NickHurst