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 9243915
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 18, 20262026-06-18T08:54:41+00:00 2026-06-18T08:54:41+00:00

I am writing a Backbone.js app using Require.js and Backbone.Marionette and testing it using

  • 0

I am writing a Backbone.js app using Require.js and Backbone.Marionette and testing it using Mocha with Chai, Sinon, and Sinon-Chai. I’ve been generally using Jarrod Overson’s Backbone Marionette with Require.JS TODO sample as a reference for application structure and Jim Newbery’s posts on testing Backbone apps as a reference for unit testing.

My problem is trying to test adding a Marionette ItemView to a Marionette Application object. I figured the best way to test that the ItemView is added is watch for its render() method to be called. Since Marionette provides a default render() implementation, I thought it best to just use a Sinon spy for the onRender() callback.

I used Squire.JS to return a stub class for my ItemView as shown below:

define(['Squire', 'backbone.marionette'], function(Squire, Marionette) {
    describe('App', function() {

        var testContext;

        beforeEach(function(done) {
            testContext = {};

            testContext.injector = new Squire();

            testContext.renderSpy = sinon.spy();

            testContext.injector.mock('app/views/Header', function() {
                var stub_template_html = "<div></div>";
                var HeaderStub = Marionette.ItemView.extend({
                    template: function(serialized_model) {
                        return _.template(stub_template_html);
                    }
                });
                return HeaderStub;
            });

            testContext.injector.require(['app/app'], function(app) {
                testContext.app = app;
                done();
            });
        });

        it ('Should add a Header view to the \'header\' region', function() {
            testContext.app.start();
            expect(testContext.renderSpy).to.be.called();
        });

When I run Mocha via Chrome, I get the error I expect: “expected spy to have been called at least once, but it was never called.” However, if I specify the Sinon spy function as the onRender() callback, as shown below

var HeaderStub = Marionette.ItemView.extend({
    // ...
    onRender: testContext.renderSpy
});

I get an error stating that the called() method is not a function.

Is there a way to specify a Sinon spy function as a method in a class definition? Alternatively, is there a better way to test this code? I’m fairly new to JavaScript, so this may be a more general problem rather than a Sinon-specific problem.

Any help is appreciated.

  • 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-18T08:54:42+00:00Added an answer on June 18, 2026 at 8:54 am

    I’m not sure what assertion library you are using, but to check if a function you spy on with sinon was called, you have to check the called property of the spy. See http://sinonjs.org/docs/#spies

    spy.called

    true if the spy was called at least once

    So your assertion should look like this:

    expect(testContext.renderSpy).to.be(true);
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm currently writing a Backbone Marionette app which ultimately amounts to about 6 different
I'm writing a backbone app, and using the built-in event handling, which uses jquery
I am writing tests for a web application using backbone and backbone.marionette through jasmine.
I'm writing a sample app using backbone.js. On update of my model I re-render
Writing my first app with CoreData. The book I'm using to guide me has
I am writing a jasmine spec against my backbone app. However, I got stuck
I'm writing an app with node.js and backbone.js. However when I try to save
There are people that are writing Backbone applications using a Backbone.d.ts. There are two
Writing an app with django, using the psycopg2 engine. It doesn't always seem to
I'm currently rewriting an old app with Backbone and Marionette. In my module file

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.