Professional Documents
Culture Documents
2. Create a jest.config.js file at the root of your project and add the following code:
module.exports = {
moduleFileExtensions: [
'js',
'json',
// tell Jest to handle `*.vue` files
'vue'
],
transform: {
// process `*.vue` files with `vue-jest`
'.*\\.(vue)$': 'vue-jest',
// process js files with `babel-jest`
'^.+\\.js$': '<rootDir>/node_modules/babel-jest'
}
}
3. Create a setup.js file at the folder tests/ of your project and add the following code:
Vue.use(Vuetify);
"scripts": {
"test": "jest"
"test:unit": "vue-cli-service test:unit
--setupTestFrameworkScriptFile=./tests/setup.js",
}
5. Create a test file (e.g., MyComponent.spec.js) in your tests/unit directory, and add the
following code:
describe('MyComponent', () => {
it('renders correctly', () => {
const mockData = {
// your mock data here
}
const wrapper = shallowMount(MyComponent, {
propsData: mockData
})
expect(wrapper.html()).toMatchSnapshot()
})
})
This is just a basic example, but you can find more information on how to use Jest and
Testing Library to test Vue 2 applications in the official documentation:
● Jest: https://jestjs.io/docs/en/getting-started
● Testing Library: https://testing-library.com/docs/vue-testing-library/intro