Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
399 views
in Technique[技术] by (71.8m points)

javascript - How to add jquery to jasmine/angularjs unittests

I have a project which is builded on plain angular.js code. We creates unittest with jasmine. But now we need to grab some 3rd party components (some directives from Angular-Bootstrap), which is also pure angular.js inside, but for testing that components some jQuery code and methods calls used. And now a lot of 3rd party tests failed with exception like [object] had no method 'trigger' and stuff like that

So my question is how to include jquery to my tests, to make 3rd party unitests valid. I run tests with Karma.

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)

Just include jquery.js to Karma's config in files array as the first item.

module.exports = function(config) {
  config.set({

    // list of files / patterns to load in the browser
    files: [
      'path/to/jquery.js',
      'path/to/angular.js'
      //..rest files      
    ],

    //rest karma options
  });
};

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...