Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>Like JasonSmith, I also recommend you test using Node.js where possible. However, due to the nature of CouchApps you often end up having to write unit tests to run in the browser, either because they interact with browser APIs you don't want to mock or because you need to test it works in a range of browsers.</p> <p>When doing browser-based unit tests I use a few little Kanso packages I hacked together to automatically present an interface for running nodeunit test suites. It's a bit rough around the edges at the moment but gets the job done.</p> <p><strong>kanso.json</strong></p> <p>Add nodeunit and nodeunit-testrunner packages to your kanso.json file and run kanso install to fetch them from the repositories.</p> <pre><code>{ "name": "example", "version": "0.0.1", "description": "example app with unit tests", "modules": ["lib", "tests"], "load": "lib/app", "dependencies": { "modules": null, "properties": null, "nodeunit": null, "nodeunit-testrunner": null } } </code></pre> <p>Notice that I've included the 'tests' directory as a module path. Any modules dropped into that directory will be used as nodeunit test suites and displayed by the nodeunit-testrunner UI.</p> <p><strong>Rewrites</strong></p> <p>You need to manually add the nodeunit-testrunner package's rewrites to your app, in my example that means editing lib/app.js to look like the following:</p> <pre><code>exports.rewrites = [ require('nodeunit-testrunner/rewrites') ]; </code></pre> <p><strong>Add some tests</strong></p> <p>Assuming we have a module lib/foo.js that looks like this:</p> <pre><code>exports.hello = function (name) { return 'hello ' + name; }; </code></pre> <p>We could add a test by adding a module at tests/test-foo.js (this can be named anything so long as it's inside the tests directory).</p> <pre><code>var foo = require('lib/foo'); exports['test for foo.hello'] = function (test) { test.equal(foo.hello('bar'), 'hello bar'); test.done(); }; </code></pre> <p>If you then push your app and visit <a href="http://localhost:5984/example/_design/example/_rewrite/test">http://localhost:5984/example/_design/example/_rewrite/test</a> in the browser you will be presented with a basic interface for running the test suites in the tests directory, either individually or all of them one after another.</p> <p>Hope that helps.</p>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
    2. VO
      singulars
      1. This table or related slice is empty.
    3. VO
      singulars
      1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload