Mindblown: a blog about philosophy.

  • Group your tests in modules

    As a plugin or library increases in size, you may want to split the source into modules to enhance its maintainability. You already saw this pattern when we discussed the structure of jQuery, whose code is made up of more than 10,000 lines. The same principle applies to the code you write to test your…

  • Noglobals and notrycatch

    QUnit offers you two check boxes, noglobals (labelled as “Check for Globals”) and notrycatch (labelled as “No try-catch”), that you can check and uncheck as needed in order to change the behavior of all tests performed on the page. The noglobals flag will fail a test if a new global variable (which is the same as adding a property to the window object)…

  • How to test asynchronous tasks

    Sometimes you need to perform a given action or repeat it over and over again after a given amount of time. Other times you want to retrieve information from a server without reloading the page. These are situations where you need to execute one or more functions asynchronously. To test asynchronous functions you can use…

  • The throws() assertion method

    We left the throws() assertion method to the end because it’s a bit different from the others. Its syntax is as follows. Method syntax: throws throws(function[, expected][, message ]) Verify that a callback throws an exception, and optionally compare the thrown error. Parameters function (Function) The function to execute. expected (Object|Function|RegExp) An Error object, an Error function…

  • Testing your code using assertions

    Assertions are the core of software testing because they allow you to verify that your code is working as expected. QUnit provides numerous methods to test your expectations that can all be accessed within a test through the assert parameter passed to the function passed to QUnit.test(). We’ll start our overview of the assertion methods by covering four…

  • Creating tests for synchronous code

    QUnit allows you to test synchronous and asynchronous code. For the moment we’ll focus on testing synchronous code because it’s the easiest way to delve into the world of QUnit. To create a test in QUnit you have to use a method called test(). Its syntax is shown here. Method syntax: QUnit.test QUnit.test(name, test) Add a…

  • Getting started with QUnit

    One of the best features of QUnit is its ease of use. Getting started with this framework is a matter of performing three simple steps. The first thing to do is to download the framework. QUnit can be downloaded in several different ways. The first method is to access its website and download the JavaScript…

  • Frameworks for unit testing JavaScript

    Do you know that joke, pretty famous among JavaScript developers, that says that you should think of a word, search Google for “<word>.js,” and if a library with that name exists, have a drink? If you didn’t, you know it now. The point of this joke isn’t to get you drunk but to highlight the…

  • Why is testing important?

    To explain why software testing is important, we’ll start with an example. How would you answer if we asked you to drive a car that nobody has ever tested in a Formula 1 race? Would you risk your life with something nobody has ever checked to see if it’s robust enough to not get destroyed…

  • Unit testing with QUnit

    This lessons covers The previous lesson was the last discussing concepts strictly related to the jQuery core. Deferred and Promise might have been tough arguments to learn but, hopefully, with our help the process has gone smoothly. It’s now time for you to enhance your skills even further. In this lesson you’ll learn other tools and techniques that every…

Got any book recommendations?