Enhance JS JavaScript Unit Testing Framework

Quick Start Guide

Adding Enhance JS to your web or server project is really easy. All you need to do is include the "enhance.js" JavaScript file in your test page. This single file contains the unit testing framework and all of the mocks, stubs and assertions you need. You can download a zip file containing enhance.js and some examples in JavaScript and CoffeeScript.

Your First Test

Here is a single page example of the whole thing. In real life, you would have your live JavaScript file that you are testing separate the the test HTML file and the test JavaScript file.

<!DOCTYPE html>
<html lang="en">
    <head>
        <meta charset="utf-8">
        <title>Enhance JavaScript Unit Testing Framework</title>
        <meta http-equiv="Content-Type" content="text/html; charset=utf-8">
        <meta name="keywords" content="enhance, javascript, unit, testing, framework">
        <meta name="description" content="Demonstration of Enhance JS, JavaScript Unit Testing Framework.">
        <meta name="author" content="Steve Fenton">
    </head>
    <body>
        <script src="enhance.js"></script>
        <script>
            Examples = (function() {
                return {
                    addTwoNumbers: function(a, b) {
                        return a + b;
                    }
                };
            }());

            ExamplesTest = (function() {
                return {
                    addTwoNumbersWith2and3Expect5: function() {
                        var result = Examples.addTwoNumbers(2, 3);
                        Assert.areIdentical(5, result);
                    },
                    addTwoNumbersWith3and3Expect6: function() {
                        var result = Examples.addTwoNumbers(3, 3);
                        Assert.areIdentical(6, result);
                    }
                };
            })();

            Enhance.discoverTests(ExamplesTest).runTests();
        </script>
    </body>
</html>