Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Jest testing recipe #3

Open
smajl opened this issue Jul 25, 2019 · 1 comment
Open

Jest testing recipe #3

smajl opened this issue Jul 25, 2019 · 1 comment

Comments

@smajl
Copy link

smajl commented Jul 25, 2019

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
Copy link
Owner

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants