NickHurst / nuxt-quasar

Nuxt module for the Quasar Framework
38 stars 6 forks source link

Jest testing recipe #3

Open smajl opened 5 years ago

smajl commented 5 years ago

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.

NickHurst commented 5 years ago

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.