Unit Testing Your Plugin with QUnit - J Query

Problem You want to raise the quality and reliability of your jQuery plugin by creating unit tests for it. How do you write and ship tests with your jQuery plugin?

Solution

The easiest method to write unit tests for a jQuery plugin is to utilize QUnit, the same unit testing framework that the jQuery project uses. With QUnit, you can write your tests right in JavaScript and ship them with your plugin for your users to run in their own browsers:

Discussion

Learning how to effectively test code is beyond the scope of this chapter. The tests written in the previous example are intended to simply show an example of what can be done with unit testing. Shipping unit tests with your plugin is another great way to show developers you are committed to the success and stability of the code that you publish. This builds trust with your user base and shows that your plugin is a good member of the jQuery plugin ecosystem. Tests also make it easy for users of your plugins to find bugs that can creep up in another runtime environment, such as a different browser. This allows you, the plugin author, to better address the bug that was found by having a working test bed, allowing you, the plugin developer, to directly address the bug that was found.


All rights reserved © 2018 Wisdom IT Services India Pvt. Ltd DMCA.com Protection Status

J Query Topics