21

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.

1 Answer 1

34

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
  });
};
Sign up to request clarification or add additional context in comments.

6 Comments

sec, maybe it wasn't first. Let me try.
Do you restart karma after changing config? You might want to double check that path to jQuery correct. It should work.
Thanks for your help. Yes, that's work. By the way - why it should be first?
A few reasons: 1. Why not? jQuery doesn't have any dependencies, but other scripts depend on it. 2. If Angular won't find jQuery at time it loads it will use its jQuery lite, instead of augmenting jQuery features.
Also make sure you put jquery first. It loads scripts sequentiallly - order is important here. I've been pulling my hair out why my .find() selector didn't work.
|

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.