First test gives "TypeError: undefined is not a function"

4,055 views
Skip to first unread message

chrizbot

unread,
Apr 29, 2011, 3:39:26 PM4/29/11
to Jasmine
Hi everyone.

I am brand new to Jasmine and want to get it testing a Backbone.js
application I just put together that runs on a Rails 2.x server.

After doing the install (via bundler) and starting the Jasmine server,
I am getting an error for a very simple test. The application runs
fine when in the normal environment.

Here is the test:

describe('Resource model', function() {
describe('when instantiated', function() {
it('should exhibit attributes', function() {
var resource = new Resource({
name: '1'
});
expect(resource.get('name'))
.toEqual('1');
});
});
});

Here are all of the errors I am getting in the console when running
this test:

Uncaught ReferenceError: jQuery is not defined
backbone.js:128Uncaught TypeError: Cannot call method 'extend' of
undefined
XXXXXX.js:1Uncaught TypeError: Cannot call method 'extend' of
undefined
XXXXXX.js:1Uncaught TypeError: Object function (attributes, options) {
attributes || (attributes = {});
if (this.defaults) attributes = _.extend({}, this.defaults,
attributes);
this.attributes = {};
this._escapedAttributes = {};
this.cid = _.uniqueId('c');
this.set(attributes, {silent : true});
this._previousAttributes = _.clone(this.attributes);
if (options && options.collection) this.collection =
options.collection;
this.initialize(attributes, options);
} has no method 'extend'
XXXXXXX.js:1Uncaught TypeError: Object function (attributes, options)
{
attributes || (attributes = {});
if (this.defaults) attributes = _.extend({}, this.defaults,
attributes);
this.attributes = {};
this._escapedAttributes = {};
this.cid = _.uniqueId('c');
this.set(attributes, {silent : true});
this._previousAttributes = _.clone(this.attributes);
if (options && options.collection) this.collection =
options.collection;
this.initialize(attributes, options);
} has no method 'extend'
XXXXXX.js:1Uncaught TypeError: Object function (attributes, options) {
attributes || (attributes = {});
if (this.defaults) attributes = _.extend({}, this.defaults,
attributes);
this.attributes = {};
this._escapedAttributes = {};
this.cid = _.uniqueId('c');
this.set(attributes, {silent : true});
this._previousAttributes = _.clone(this.attributes);
if (options && options.collection) this.collection =
options.collection;
this.initialize(attributes, options);
} has no method 'extend'
XXXXXXX.js:1Uncaught TypeError: Object function (attributes, options)
{
attributes || (attributes = {});
if (this.defaults) attributes = _.extend({}, this.defaults,
attributes);
this.attributes = {};
this._escapedAttributes = {};
this.cid = _.uniqueId('c');
this.set(attributes, {silent : true});
this._previousAttributes = _.clone(this.attributes);
if (options && options.collection) this.collection =
options.collection;
this.initialize(attributes, options);
} has no method 'extend'
XXXXX.js:1Uncaught TypeError: Cannot call method 'extend' of undefined
XXXXXX.js:1Uncaught TypeError: Cannot call method 'extend' of
undefined
XXXXX.js:1Uncaught TypeError: Cannot call method 'extend' of undefined
XXXXX.js:1Uncaught TypeError: Cannot call method 'extend' of undefined
jquery-ui.min.js:10Uncaught ReferenceError: jQuery is not defined
jquery.flot.js:28Uncaught ReferenceError: jQuery is not defined
prototype.js:4071Uncaught TypeError: Object [object Object] has no
method 'dispatchEvent'

When I view source for the Jasmine page being run all of the needed
JavaScript files from the project are being included.

I even tried to specifically add the jquery.min.js and backbone.js
files to the top of the jasmine.yml src_files in case there was some
JavaScript ordering issue.

Is there something really simple/stupid I am missing here?

Any help is appreciated. Thanks!

Rajan Agaskar

unread,
Apr 29, 2011, 9:49:05 PM4/29/11
to jasmi...@googlegroups.com
The default jasmine install just loads all your source files in random order unless you specify a load order. It sounds like you'll want to specify some load order dependencies. 

If you look at jasmine.yml, you'll probably want to set src_file so it looks something like the following: 

src_files:
  - public/javascripts/vendor/jquery-1.5.2.js
  - public/javascripts/vendor/underscore.js
  - public/javascripts/vendor/backbone.js
  - public/javascripts/**/*.js

What this does is make jasmine load Jquery, then underscore, then backbone (etc). After it loads your named dependencies, it will load all other javascripts in your public/javascripts folder.

Hope this helps!

Thanks!

Rajan 



--
You received this message because you are subscribed to the Google Groups "Jasmine" group.
To post to this group, send email to jasmi...@googlegroups.com.
To unsubscribe from this group, send email to jasmine-js+...@googlegroups.com.
For more options, visit this group at http://groups.google.com/group/jasmine-js?hl=en.


chrizbot

unread,
Apr 29, 2011, 10:36:37 PM4/29/11
to Jasmine
Yep, that did it. Thanks for the quick reply!
Reply all
Reply to author
Forward
0 new messages