Cannot call method 'start' of undefined error using Backbone.history.start() and QUnit


HOME ยป Web Design

I'm currently writing unit tests for my backbone.js application,
and I'm having a few problems testing the backbone routes with
QUnit.


Unfortuntely, I'm getting the following error when
attempting to run the test. It appears to be on the QUnit module setup
when I create an instance of my Backbone Router:

/>

Cannot call method 'start' of undefined

/>

Here is my code for the test's module setup (called on document
ready):


var router;
module("Test Router", {

setup: function () {
router = new TestRouter();

},
teardown: function () {
r

I'm following this example
https://github.com/codebrew/backbone-rails#example-usage for the
backbone-rails gem. It works fine for models that have one word names
but I get the Uncaught TypeError: Cannot call method 'bind' of
undefined
error if I try to follow the same pattern for a model
with two names. Here's what I did:


rails new blog />

I added the rails-backbone gem into the
Gemfile then


bundle install
rails g
backbone:install
rails g scaffold FriendRequest
sender_gender:string recipient_gender:string
rake db:migrate />rails g backbone:s
Web Design

I am trying to start history with backbone however I get the
error:


Cannot call method 'start' of undefined

/>

Here is a link to the full code :
http://pastebin.com/pNsYghgE


I have jquery, underscore,
and backbone js include before this code so I would imagine this
should work based off the documentation. I am using backbone 0.9.2.
What am I doing wring here?


EDIT: ANSWER


I
want not creating an instance of my routers so I added this code to
before I called Backbone.history.start():


//initialize
all routes
_(this.modules()).each(function(module, mo
Web Design

When I run the r.js optimizer over my Backbone.js app, I get this
error:


Uncaught TypeError: undefined is not a
function

It appears in the middle of the
Backbone.js section of the output.


I removed bits of code
until I found out what was causing it, and it seems to be when I call
Backbone.history.start();.


I've created a
simple app to replicate the bug, which I've posted below. Basically,
it creates a route and 'console.log's 'home'. It works fine when not
optimized.


To optimize the app, I use:


node
r.js -o app.build.js

Web Design

I'd like to have multiple routers living on a single page for
modularity. I initialize the routers on
$(document).ready() in different js files. When I had
just one router that worked fine because I could call
History.start() right after initializing the router, but
now that I have multiple routers that could be initialized from
different files, I'm not sure when to call
History.start().


For example:

/><script src="router1.js"
type="text/javascript"></script>
<script
src="router2.js" type="text/javascript"></script> />

In router1.js:


<
Web Design

I'm currently writing unit tests for my backbone.js application,
and I'm having a few problems testing the backbone routes with
QUnit.


Unfortuntely, I'm getting the following error when
attempting to run the test. It appears to be on the QUnit module setup
when I create an instance of my Backbone Router:

/>

Cannot call method 'start' of undefined

/>

Here is my code for the test's module setup (called on document
ready):


var router;
module("Test Router", {

setup: function () {
router = new TestRouter();

},
teardown: function () {
r
Web Design
QUnit has been used for some time so this has got to be a mistake
somewhere on my part but I can't figure out where the problem is:I am
using QUnit 1.12.0 and see this behavior in both IE11 and Chrome
31.0.1650.63Since the QUnit.config.semaphore value starts off as
undefined, the calls to QUnit.stop() and QUnit.start() do not actually
decrement or increment the value.For example, line 488 of
qunit-1.12.0.js (which is the first line of the stop() method)
is:config.semaphore += count || 1;
Programming Languages

- Technology - Languages
+ Webmasters
+ Development
+ Development Tools
+ Internet
+ Mobile Programming
+ Linux
+ Unix
+ Apple
+ Ubuntu
+ Mobile & Tablets
+ Databases
+ Android
+ Network & Servers
+ Operating Systems
+ Coding
+ Design Software
+ Web Development
+ Game Development
+ Access
+ Excel
+ Web Design
+ Web Hosting
+ Web Site Reviews
+ Domain Name
+ Information Security
+ Software
+ Computers
+ Electronics
+ Hardware
+ Windows
+ PHP
+ ASP/ASP.Net
+ C/C++/C#
+ VB/VB.Net
+ JAVA
+ Javascript
+ Programming
Privacy Policy - Copyrights Notice - Feedback - Report Violation 2018 © BigHow