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

Related to : Cannot call method 'start' of undefined error using Backbone.history.start() and QUnit
rails-backbone gem error for model with two-word names: Uncaught TypeError: Cannot call method 'bind' of undefined
Web Design

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
Backbone history start not working
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
Backbone.history.start() throws a TypeError when r.js -o is used
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

Backbone > Multiple Routers and History.start
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:


<
Cannot call method 'start' of undefined error using Backbone.history.start() and QUnit
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
QUnit.config.semaphore is undefined and so does not affect stop() or start()
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;

Privacy Policy - Copyrights Notice - Feedback - Report Violation - RSS 2017 © bighow.org All Rights Reserved .