Permalink
Browse files

updated README to include information on running tests in the browser

  • Loading branch information...
1 parent 5693698 commit cd9bd213a4a327ddb6b2f76a42018829dd8fcee1 @caolan committed Nov 21, 2010
Showing with 48 additions and 1 deletion.
  1. +48 −1 README.md
View
@@ -1,10 +1,12 @@
Nodeunit
========
-A simple unit testing tool based on the node.js assert module.
+Simple syntax, powerful tools. Nodeunit provides easy async unit testing for
+node.js and the browser.
* Simple to use
* Just export the tests from a module
+* Works with node.js and in the browser.
* Helps you avoid common pitfalls when testing asynchronous code
* Easy to add test cases with setUp and tearDown functions if you wish
* Flexible reporters for custom output, built-in support for HTML and jUnit XML
@@ -233,6 +235,51 @@ bin/nodeunit.json for current available options.
* __--help__ - show nodeunit help
+Running unit tests in the browser
+---------------------------------
+
+Nodeunit tests can also be run inside the browser. For example usage, see
+the examples/browser folder. The basic syntax is as follows:
+
+__test.html__
+
+ <html>
+ <head>
+ <title>My tests</title>
+ <script src="nodeunit.js"></script>
+ <script src="suite1.js"></script>
+ <script src="suite2.js"></script>
+ </head>
+ <body>
+ <script>
+ nodeunit.run({
+ 'suite1': suite1,
+ 'suite2': suite2
+ });
+ </script>
+ </body>
+ </html>
+
+Here, suite1 and suite2 are just object literals containing test functions or
+groups, as would be returned if you did require('test-suite') in node.js:
+
+__suite1.js__
+
+ this.suite1 = {
+ 'example test': function (test) {
+ test.ok(true, 'everything is ok');
+ test.done();
+ }
+ };
+
+If you wish to use a commonjs format for your test suites (using exports), it is
+up to you to define the commonjs tools for the browser. There are a number of
+alternatives and its important it fits with your existing code, which is
+why nodeunit does not currently provide this out of the box.
+
+In the example above, the tests will run when the page is loaded.
+
+
Adding nodeunit to Your Projects
--------------------------------

0 comments on commit cd9bd21

Please sign in to comment.