vendredi 7 juillet 2017

Karma vue unit test Undefined is not an object $.fn.jquery

guys, I have a little problem with Karma. When I run it, I have this error

PhantomJS 2.1.1 (Windows 8 0.0.0) ERROR TypeError: undefined is not an object (evaluating '$.fn.jquery') at webpack:///src/assets/js/bootstrap.js:13:2 <- index.js:53813

At the beginning Bootstrap required jQuery and I added it. Place below two files hoping they can bo of help to solve the problem.

webpack.test.config.js

// This is the webpack config used for unit tests.

var utils = require('./utils')
var webpack = require('webpack')
var merge = require('webpack-merge')
var baseConfig = require('./webpack.base.conf')

var webpackConfig = merge(baseConfig, {
  // use inline sourcemap for karma-sourcemap-loader
  module: {
    rules: utils.styleLoaders()
  },
  devtool: '#inline-source-map',
  resolveLoader: {
    alias: {
      // necessary to to make lang="scss" work in test when using vue-loader's ?inject option 
      // see discussion at http://ift.tt/2txDF16
      'scss-loader': 'sass-loader'
    }
  },
  plugins: [
    new webpack.DefinePlugin({
      'process.env': require('../config/test.env'),
      'jQuery': require('jquery'),
      '$': require('jquery')
    })
  ]
})

// no need for app entry during tests
delete webpackConfig.entry

module.exports = webpackConfig

karma.conf.js

// This is a karma config file. For more details see
//   http://ift.tt/1RKjVdX
// we are also using it with karma-webpack
//   http://ift.tt/1dZymhu

var webpackConfig = require('../../build/webpack.test.conf')

module.exports = function (config) {
  var absolute_root = process.cwd() + '/';
  config.set({
    // to run in additional browsers:
    // 1. install corresponding karma launcher
    //    http://ift.tt/2qXzYTH
    // 2. add it to the `browsers` array below.
    browsers: ['PhantomJS'],
    frameworks: ['mocha', 'sinon-chai', 'phantomjs-shim'],
    reporters: ['spec', 'coverage'],
    files: [
      './index.js'
    ],
    preprocessors: {
      './index.js': ['webpack', 'sourcemap']
    },
    webpack: webpackConfig,
    webpackMiddleware: {
      noInfo: true
    },
    coverageReporter: {
      dir: './coverage',
      reporters: [
        { type: 'lcov', subdir: '.' },
        { type: 'text-summary' }
      ]
    }
  })
}

How can I resolve this problem?

Aucun commentaire:

Enregistrer un commentaire