An open API service indexing awesome lists of open source software.

https://github.com/ehsan-shv/nuxt-jest

Nuxt-Jest common warnings.
https://github.com/ehsan-shv/nuxt-jest

jest nuxtjs vuejs vuelidate vuex

Last synced: 6 months ago
JSON representation

Nuxt-Jest common warnings.

Awesome Lists containing this project

README

          

## nuxt-jest common warnings:

```bash
# install dependencies
$ npm install

# serve with hot reload at localhost:3000
$ npm run dev

# run test
$ npm run test
```
---

**1-[Vue warn]: Unknown custom element: - did you register the component correctly? For recursive components, make sure to provide the "name" option.**

component:




Home


test:

import { mount } from '@vue/test-utils'
import Header from '~/components/Header/Header'

describe('Header', () => {
test('is a Vue instance', () => {
const wrapper = mount(Header)
expect(wrapper.vm).toBeTruthy()
})})
solution:

import { mount, RouterLinkStub } from '@vue/test-utils'
import Header from '~/components/Header/Header'

describe('Header', () => {
test('is a Vue instance', () => {
const wrapper = mount(Header, {
stubs: {
NuxtLink: RouterLinkStub
}
}) expect(wrapper.vm).toBeTruthy()
})})

**2-[Vue warn]: Error in render: "TypeError: Cannot read property 'state' of undefined"**

component:




{{ $store.state.title }}



test:

import { mount } from '@vue/test-utils'
import Main from '~/components/Main/Main'

describe('Main', () => {
test('is a Vue instance', () => {
const wrapper = mount(Main)
expect(wrapper.vm).toBeTruthy()
})})

solution:

import { mount, createLocalVue } from '@vue/test-utils'
import Vuex from 'vuex'
import Main from '~/components/Main/Main'

const localVue = createLocalVue()
localVue.use(Vuex)

const store = new Vuex.Store({
state: {
title: 'nuxt-jest'
}
})

describe('Main', () => {
test('is a Vue instance', () => {
const wrapper = mount(Main, {
localVue,
store
})
expect(wrapper.vm).toBeTruthy()
})})
**3-[Vue warn]: Missing required prop: "title"**

component:



{{ title }}






export default {
name: 'Footer',
props: {
title: {
type: String,
required: true
}
}}

test:

import { mount } from '@vue/test-utils'

import Footer from '~/components/Footer/Footer'

describe('Footer', () => {
test('is a Vue instance', () => {
const wrapper = mount(Footer)
expect(wrapper.vm).toBeTruthy()
})})

solution:

import { mount } from '@vue/test-utils'

import Footer from '~/components/Footer/Footer'

describe('Footer', () => {
test('is a Vue instance', () => {
const wrapper = mount(Footer, {
propsData: { title: 'footer' }
}) expect(wrapper.vm).toBeTruthy()
})})

**4- [Vue warn]: Error in render: "TypeError: Cannot read property '[property name]' of undefined". ([Vuelidate](https://vuelidate.js.org/))**

component:








import { required } from 'vuelidate/lib/validators'

export default {
name: 'Side',
data () {
return {
name: ''
}
}, validations: {
name: {
required
}
}}

test:

import { mount, createLocalVue } from '@vue/test-utils'
import Side from '@/components/Side/Side'

describe('Side', () => {
test('is a Vue instance', () => {
const wrapper = mount(Side)
expect(wrapper.vm).toBeTruthy()
})})

solution:

import { mount, createLocalVue } from '@vue/test-utils'
import Side from '@/components/Side/Side'
import Vuelidate from 'vuelidate'

const localVue = createLocalVue()

localVue.use(Vuelidate)

describe('Side', () => {
test('is a Vue instance', () => {
const wrapper = mount(Side, {
localVue
})
expect(wrapper.vm).toBeTruthy()
})})