Skip to content

Instantly share code, notes, and snippets.

@phuochau
Last active March 26, 2018 17:46
Show Gist options
  • Save phuochau/328af18a084ac43a85388d3e7f5f3f15 to your computer and use it in GitHub Desktop.
Save phuochau/328af18a084ac43a85388d3e7f5f3f15 to your computer and use it in GitHub Desktop.
Sample configuration for using Jest and vue-test-utils in nuxt.js project
// package.json
"jest": {
"roots": [
"<rootDir>/tests/unit"
],
"moduleNameMapper": {
"[\\s\\S]*.(jpg|jpeg|png|gif|eot|otf|webp|svg|ttf|woff|woff2|mp4|webm|wav|mp3|m4a|aac|oga)$": "<rootDir>/tests/unit/__mocks__/fileMock.js",
"[\\s\\S]*.(css|less)$": "<rootDir>/tests/unit/__mocks__/styleMock.js",
"~/([a-zA-Z0-9/.\\-_]*)": "<rootDir>/src/$1"
},
"moduleFileExtensions": [
"js",
"vue"
],
"transform": {
"^.+\\.js$": "<rootDir>/node_modules/babel-jest",
".*\\.(vue)$": "<rootDir>/node_modules/jest-vue-preprocessor"
},
"modulePathIgnorePatterns": [
"<rootDir>/tests/unit/coverage/*"
],
"coverageDirectory": "<rootDir>/tests/unit/coverage/",
"coverageReporters": [
"html",
"json"
]
}
// __mocks__/styleMock.js
module.exports = {}
// __mocks__/fileMock.js
module.exports = 'test-file-stub'
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment