qunit

What are some JavaScript Unit Testing and Mocking Frameworks you have used?

My main JavaScript framework is jQuery so I would like my unit test and mocking frameworks to be compatible with that. I'd rather not have to introduce another JavaScript framework. I am currently using QUnit for unit testing and Jack for mocking, but I am pretty new to the whole unit testing of JavaScript. Does anyone else have a bett...

Can you create 'Dynamic' tests with MS Test Suite?

I'm using QUnit to test some JQuery, and I've got Watin to load up the test page and parse out the test results, but I'm wondering if there's a way to dynamically generate the tests from the page using the MS Test suite rather than having to write a Test function for each test? I'm just trying to reduce the amount of code having to be w...

Testing checkbox click

I have started testing my UI using qUnit, so I need to simulate some user interaction. Is it possible to "simulate" a user clicking a checkbox using javascript ? ...

Qunit parameterized tests and mocking

I have two questions: Can you have parameterised unit tests in qunit? How do you do mocking with qunit e.g. mocking a getJSON call? Thanks ...

QUnit with Ajax! QUnit passes the failing tests!

I am looking into QUnit for JavaScript unit testing. I am in a strange situation where I am checking against the value returned from the Ajax call. For the following test I am purposely trying to fail it. // test to check if the persons are returned! test("getPersons", function() { getPersons( func...

QUnit Unit Testing: Test Mouse Click

I have the following HTML code: <div id="main"> <form Id="search-form" action="/ViewRecord/AllRecord" method="post"> <div> <fieldset> <legend>Search</legend> <p> <label for="username">Staff name</label> <input id="username" name="username" type="text" value="" /> ...

How to unit test jQuery keyboard events?

Is there a way to test JavaScript keyboard event handlers (for keypress, keyup, keydown events)? I know I can declare event handlers like this: function keyUpEvHandler(e) { ... // code here } $('#myId').keyup(keyUpEvHandler); and then just run this function in unit tests, but I will have to prepare event argument object to be th...

Testing Javascript that Manipulates the DOM

I've been looking into javascript test suites and I have found QUnit to be very interesting. I understand how to test computational code, but... How do you test javascript applications written primarily for DOM manipulation? it seems like testing the position/color/etc of DOM elements would be a moot point because you'd end up doing so...

QUnit output: visual separation of modules

My tests may look like this: module("some module"); test("test A", ...); test("test B", ...); module("other module"); test("test C", ...); test("test D", ...); The output of QUnit will look like this 1. test A (0, 0, 0) 2. test B (0, 0, 0) 3. test C (0, 0, 0) 4. test D (0, 0, 0) Is it possible to make QUnit output the module nam...

Recommended structure for testing Javascript with QUnit in ASP.NET

I have a standard ASP.NET MVC (version 2 preview 2) solution with the actual project and server-side unit tests in separate projects. Because this project is very client-side heavy, I want to make a ClientTest project as well that uses QUnit to test the main project. I've thought of creating a regular ASP.NET webforms project with a ...

QUnitAdaptor for JSTestDriver passing failed test!

Hi all: I have a very strange case here when using QUnitAdaptor to test my QUnit tests. It actually passed a test which is supposed to fail: test("very simple test", function() { var somevar = true; equals(somevar, false, "test"); }); The above test passed when I ran it after capturing browser programmatically. Has anyone experienc...

How to unit test a jQuery selector?

Hi all: Just a quick question... I currently have the following jQuery code with a selector in it. var ID = "idControl" function doesTreeViewExist() { if($('#' + ID).length == 0) { return false; } else { return true; } } I was wondering how do I write the test to test the selector using QUnit? ...

qUnit Teardown method

Is it possible to have teardown methods that run after every test in qUnit? If not, are there any plugins around that will do this? ...

Running JavaScript unit tests headlessly in a Continuous Integration build

I have a webapp build plan running on a Continuous Integration system (Atlassian Bamboo 2.5). I need to incorporate QUnit-based JavaScript unit tests into the build plan so that on each build, the Javascript tests would be run and Bamboo would interpret the test results. Preferably I would like to be able to make the build process "stan...

How to extract QUnit results from the document

When QUnit adds the test result details to your HTML document, it thoughtfully wraps the numbers of tests taken, passed and failed inside span elements, each with its own class, to let you recover these three numbers programmatically. However, even though I can see the spans in the finished HTML, I can't find them when I search with jQu...

Javascript Sandbox unit testing

I am using QUnit, which is excellent. I have enclosed my JS app in the (function () {})(); sandbox. This hides a lot of code that I don't want public, but I also need to test that code. Here is an example of how this works: (function () { var PublicAPI = window.PublicAPI = {}; PublicAPI.publicFunction = function (fo...

How to write unit test to assert the value of a jQuery element

I am using jQuery 1.4.1 and here is a simple code. buildCol1: function() { var col = $('<select />', {className: 'col1' }).append($('<option />')); return $('<td />').append(col); }, I am using qunit . In this case the method call is returning a jquery element. Since I am writing a test I should have something like s = "<td><sele...

Ajax unit testing mocking using Jack

I am using Jack as JavaScript mocking library. http://github.com/keronsen/jack . I am also using qunit. I have following AJAX call in my javascript code which I am tring to write test for. $.ajax({ url: $('#advance_search_form').attr('action'), type: 'post', dataType: 'json', data: parameterizedData, success: functi...

why attach to window [edited]

I was looking over the code for qunit. My question is why would you want to attach the qunit object via property to window object. Here is the link to the file. Look at line 11. If I look at a unit test run using firebug you can see it is a property of window. [edit] Additional: Is there a specific reference for best practice for dec...

Excluding files from being deployed with Capistrano while still under version control with Git

I want to start testing the JavaScript in my Rails apps with qUnit and I'm wondering how to keep the test JavaScript and test runner HTML page under version control (I'm using Git, of course) but keep them off the production server when I deploy the app with Capistrano. My first thought is to let Capistrano send all the code over as usua...