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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 23, 20262026-05-23T19:46:58+00:00 2026-05-23T19:46:58+00:00

I have a dynamic page built with jQuery. Html pieces are loaded from mustache

  • 0

I have a dynamic page built with jQuery. Html pieces are loaded from mustache templates. These templates are downloaded from a url, and I would like to unit test the overall html construction :

The JsTestDriver test is :

AppTest = TestCase("AppTest")

AppTest.prototype.test = function() {
    var actualHtml = "";

    getHtml({ "title": "title", "header": "header", "text": "text", "authors": [ {"firstname": "firstname", "lastname": "lastname"} ] }, function(html) {
        actualHtml = html;
    });

    assertEquals("expected html", actualHtml);
};

And the code :

function getHtml(json, resultFunc) {
   jQuery.ajax({
            url: "url/to/mustache/template",
            success: function(view) {
                    resultFunc(mergeArticleModelAndView(json, view));
            },
            error: function(jqXHR, textStatus, errorThrown) {
                    resultFunc(textStatus + " errorThrown: " + errorThrown);
            },
            dataType: 'text',
            async: false 
    });
}

Then I launch the tests and the result is :

$ java -jar JsTestDriver-1.3.2.jar --port 9876 --browser /usr/bin/firefox --tests all
F
Total 1 tests (Passed: 0; Fails: 1; Errors: 0) (8,00 ms)
  Firefox 5.0 Linux: Run 1 tests (Passed: 0; Fails: 1; Errors 0) (8,00 ms)
    AppTest.test failed (8,00 ms): AssertError: expected "expected html" but was "error errorThrown: [Exception... \"Component returned failure code: 0x80004005 (NS_ERROR_FAILURE)\"  nsresult: \"0x80004005 (NS_ERROR_FAILURE)\"  location: \"JS frame :: http://localhost:9876/test/main/js/jquery.min.js :: <TOP_LEVEL> :: line 16\"  data: no]"
  ()@http://localhost:9876/test/test/js/app_test.js:25

So the error callback has been called, and I don’t understand why it breaks with JsTestDriver, and the code works when calling the application manually with a browser

Last thing, the jsTestDriver.conf :

server: http://localhost:9876

load:
  - test/js/app_test.js
  - main/js/jquery.min.js
  - main/js/jquery.mustache.js
  - main/js/app.js

Thank you for your advices. More generally, what unit test frameworks do you use for javascript and command line testing with DOM and jQuery ?

  • 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-05-23T19:46:58+00:00Added an answer on May 23, 2026 at 7:46 pm

    Yes it is possible to do quite the same with jquery :

    Test code (just the setup the test is the same) :

    TestCase("AppTest", {
        setUp: function() {
            this.xhr = Object.create(fakeXMLHttpRequest);
            this.xhr.send=function () {
                this.readyState = 4;
            };
            this.xhr.getAllResponseHeaders=stubFn({});
            this.xhr.responseText="<expected data>";
            jQuery.ajaxSettings.isLocal=stubFn(true);
            jQuery.ajaxSettings.xhr=stubFn(this.xhr);
        },
    // same test method
    

    And the production code :

    function getHtml(model, resultFunc) {
            $.get("/url/to/template", function(view) {
                    resultFunc(mergeArticleModelAndView(model, view));
            });
    }
    

    That’s the solution that we have chosen.

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

Sidebar

Related Questions

I have an asp.net view/page (dynamic) that is built up of nested Html.RenderPartials. The
Embedded custom-tag in dynamic content (nested tag) not rendering. I have a page that
I have a custom built ajax [div] based dynamic dropdown. I have an [input]
here's one for the brightest of you: I've built a huge dynamic child page
I have a dynamic web page that after clicking a link, I insert a
I have a highly dynamic single page interface where various user events trigger new
I have a dynamic query that returns around 590,000 records. It runs successfully the
I have a Dynamic Data Entities Web Application that uses a database with GUIDs
I have a dynamic class that serves as a storage container for configuration settings.
How can I have a dynamic variable setting the amount of rows to return

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.