Skip to content
This repository has been archived by the owner on Jul 26, 2023. It is now read-only.

TypeError: 'undefined' is not a function (evaluating 'jasmine.addMatchers') #168

Closed
br1anchen opened this issue Jan 15, 2014 · 9 comments
Closed

Comments

@br1anchen
Copy link

I am using yeoman angular-generator to set up the project, then by default it is using karma runner to make the unit test. The problem is after includes the jasmine-jquery pulgin, the karma unit test does not work.
The error message is :

TypeError: 'undefined' is not a function (evaluating 'jasmine.addMatchers')
at ../app/bower_components/jasmine-jquery/lib/jasmine-jquery.js:716
at ../node_modules/karma-jasmine/lib/adapter.js:166

Here is my karma.conf.js:

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

basePath: '',

frameworks: ['jasmine'],

files: [
  'app/bower_components/jquery/jquery.js',
  'app/bower_components/jasmine-jquery/lib/jasmine-jquery.js',
  'app/bower_components/angular/angular.js',
  'app/bower_components/angular-mocks/angular-mocks.js',
  'app/bower_components/angular-resource/angular-resource.js',
  'app/bower_components/angular-cookies/angular-cookies.js',
  'app/bower_components/angular-bootstrap/ui-bootstrap.js',
  'app/bower_components/angular-route/angular-route.js',
  'app/bower_components/angular-ui-router/release/angular-ui-router.js',
  'app/bower_components/node-uuid/uuid.js',
  'app/bower_components/x2js/xml2json.js',

  'app/scripts/config/App_Constants.js',
  'app/scripts/*.js',
  'app/scripts/**/*.js',
  'test/spec/**/*.js'
],

exclude: [],

reporters: ['progress'],

port: 8080,

logLevel: config.LOG_INFO,

autoWatch: true,

browsers: ['PhantomJS'],

singleRun: false

});
};

I installed the karma-jasmine by npm, the only thing I would mentioned is all the bower_components arein the app directory by yeoman grunt configuration. If I put all the bower_components on the root directory of the project with bower.json (since in the yeoman generator it use .bowerrc file to redirect the install directory to app/bower_components which I would like to keep), then the test will work. So the only difference is the bower_components place. I have a guess with npm package place which is also under the root directory, would it be the case? But anyway I want to ask for a good solution for that, since I think the directory structure of yeoman workflow is quite good way to start :)

PS: I am using jasmine-jquery 2.0.0 and karma-jasmine 0.1.5

@javier-delgado
Copy link

I had the same problem. It seems to be an issue with the version of jasmine-jquery.js and the version of jasmine.js that karma is using. I found a workaround, I use an older version of jasmine-jquery (1.3.1): http://cloud.github.com/downloads/velesin/jasmine-jquery/jasmine-jquery-1.3.1.js

@travisjeffery
Copy link
Collaborator

karma-jasmine only supports jasmine 1.x so you need to use jasmine-jquery < 2.

edit (july 7): karma-jasmine v0.2.0+ now supports jasmine 2

@br1anchen
Copy link
Author

Thank you for help

@hxu
Copy link

hxu commented Feb 1, 2014

As a note for future users who are trying to get this to work, you don't need to go as far back as version 1.3. 1.3 didn't have the getJSONFixtures functionality I needed, but 1.7 does and it worked for me.

@thebookworm101
Copy link

where can we download 1.7 from @hxu ?

@hxu
Copy link

hxu commented Feb 15, 2014

@thebookworm101 If you're using bower, you can set the version in your bower file. Or, here's the link to that git tag on GitHub.

@mooreniemi
Copy link

thanks for making a note of this guys! for posterity a reminder to others: make sure to restart karma to see this change take effect. :)

@tomwganem
Copy link

In regards to the comment that karma-jasmine only supports jasmine 1.x, karma-jasmine does in fact now support jasmine 2.0. Put "karma-jasmine": "~0.2.0" in your devDependencies.

@travisjeffery
Copy link
Collaborator

thanks, updated my comment

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

7 participants