Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 9039365
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 16, 20262026-06-16T09:42:45+00:00 2026-06-16T09:42:45+00:00

I have been trying to integrate unit testing with my Backbone models through an

  • 0

I have been trying to integrate unit testing with my Backbone models through an express node.js project, and having difficulties grasping exactly how to accomplish this task.
(sidenote: I come from a lot of Java background, and I realize there are differences, but I am loving the simplicity and elegance of the node development environment so far.)

My problem stems from the following issue, backbone models need to be exposed to the browser in order to run within it, whereas testing through mocha is “server side” on the node runtime environment.

Here is an example of what I am talking about:

Model File: /public/js/backbone/models.js

var SomeModel = Backbone.Model.extend({...});

Server Side Test: /test/backbone/models-test.js

???

I write ??? because normal unit testing via server side you just do:

var SomeModule = require('./someModule');

and go about your merry way. Obviously, since the browser is not running within Node, modules aren’t readily available.

I have read some posts stating you need to wrap your browser-side javascript within require.js which will put those javascript files into the node namespace automagically allowing you to do a require and go on with your testing. However, I have not found a coherent way of accomplishing such a task, and I have tried searching around for examples, but can’t seem to find something that applies. Granted, it very well might be my general lack of knowledge for this framework since I’m still wrapping my head around the entire idea of how things are scoped in javascript, injection of dependencies, etc.

Any help would be much appreciated, and I apologize if this question has been asked a million times already, I’m sure it has, and I’m asking it in an incorrect way.

Thanks in advance.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-16T09:42:46+00:00Added an answer on June 16, 2026 at 9:42 am

    If you have some node-only code (like your unit tests if you only plan to execute them under node), you can take this approach:

    • npm install backbone
    • var Backbone = require('backbone');
    • Just make sure the version of backbone you get from NPM is identical to the version you send to the browser. You can even symlink public/js/backbone.js to the file under node_moules/backbone/backbone.js if you like.

    If you have browser-only code, you can either use the Backbone global variable or a require.js shimmed version of it if you like.

    If you have code (like your Models) that you want to run in the browser but also work in node, the cleanest solution is to code it CommonJS (node) style using var Backbone = require('backbone'); and run it that way in node, but wrap it with a requirejs/AMD wrapper when you send it to the browser and use require.config & require.paths to map ‘backbone’ to your backbone.js file.

    Details in this very popular question/answer:

    https://stackoverflow.com/a/10914666/266795

    See also:

    http://backbonetutorials.com/organizing-backbone-using-modules/

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have been trying to figure out how to integrate a node.js app into
I have been trying to integrate Facebook with my app to allow users to
I have been Googling a problem that I have with trying to integrate the
I have been trying to integrate my very simple voice recorder app with the
I have been trying to integrate Open Graph into my website. It is basically
I've been trying to integrate deploying java .war 's in GlassFish V3 through Maven.
I have been trying to integrate Sonar with our Jenkins continous Integration system. I
I have been struggling to integrate ITKinto Qt project. I had Googled but i
I have been trying to integrate Spring (3.0.4 and 3.0.5) MVC with Apache Tiles
So I have recently been trying to integrate CAS and Alfresco on an Oracle

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.