E
E
Emil Rakhmatullin2021-09-06 17:58:49
Unit testing
Emil Rakhmatullin, 2021-09-06 17:58:49

How to unit test Vue components in a Laravel application?

I did everything as the documentation says: Testing - Vue.js .

Here are the JEST settings in package.json:

"jest": {
    "moduleFileExtensions": [
        "js",
        "json",
        "vue"
    ],
    "transform": {
        ".*\\.(vue)$": "<rootDir>/node_modules/vue-jest",
        "^.+\\.js$": "<rootDir>/node_modules/babel-jest"
    },
    "collectCoverage": true,
    "collectCoverageFrom": ["**/*.{js,vue}", "!**/node_modules/**"]
},


Here is the test:
import { mount } from '@vue/test-utils'
import OrdersIndex from "../components/orders/OrdersIndex"

describe('Component OrdersIndex', () => {
    test('является экземпляром Vue', () => {
        const wrapper = mount(OrdersIndex)
        expect(wrapper.isVueInstance()).toBeTruthy()
    })
})


But when the command is executed npm test, JEST swears at all exports and imports in all components.

Answer the question

In order to leave comments, you need to log in

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question