[Vuejs]-Jest import common plugins like Vee Validate before each test

0👍

You can use the setupFiles property in jest.config.js:

module.exports = {
  rootDir: path.resolve(__dirname, '../../'),
  moduleFileExtensions: [
    'js',
    'json',
    'vue'
  ],
  transform: {
    '^.+\\.js$': 'babel-jest',
    '.*\\.(vue)$': 'vue-jest',
    '.+\\.(css|styl|less|sass|scss|svg|png|jpg|ttf|woff|woff2)$': 'jest-transform-stub',
    'vee-validate/dist/rules': 'babel-jest'
  },
  transformIgnorePatterns: [
    '<rootDir>/node_modules/(?!(vuetify)|(vue-material-design-icons)|(vee-validate/dist/rules)|(vue-picture-input/PictureInput.vue))'
  ],
  setupFiles: [
    './tests/unit/jest.setup.js'
  ],
  reporters: ['default', 'jest-junit'],
  collectCoverageFrom: [
    'src/**/*.{js,vue}',
    '!src/**/Application/*.js'
  ],
  testPathIgnorePatterns: [
    '<rootDir>/node_modules/',
    '<rootDir>/vendor/',
    '<rootDir>/web/'
  ],
  coverageThreshold: {
    global: {
      branches: process.env.COVERAGE_THRESHOLD_GLOBAL_BRANCH || 37,
      functions: process.env.COVERAGE_THRESHOLD_GLOBAL_FUNCTIONS || 40,
      lines: process.env.COVERAGE_THRESHOLD_GLOBAL_LINES || 50
    }
  }
}

Leave a comment