Labs/Jetpack/JEP/31: Difference between revisions

Jump to navigation Jump to search
→‎Test Modules: moved test runner object docs to jep-28 and linked to them
(→‎Manifest: added 'url' and 'license')
(→‎Test Modules: moved test runner object docs to jep-28 and linked to them)
Line 87: Line 87:
==== Test Modules ====
==== Test Modules ====


A test module is any module located in one of the top-level module directories specified by the <tt>"tests"</tt> key in <tt>package.json</tt> whose filename starts with the prefix <tt>test-</tt>.  All its exported functions are assumed to be test cases or a suite of test cases; each is called with a single argument, <tt>test</tt>, which represents the test runner.
A test module is any module located in one of the top-level module directories specified by the <tt>"tests"</tt> key in <tt>package.json</tt> whose filename starts with the prefix <tt>test-</tt>.  All its exported functions are assumed to be test cases or a suite of test cases; each is called with a single argument, <tt>test</tt>, which is a [[Labs/Jetpack/JEP/28#Test_Runner_Objects|Test Runner Object]].
 
The <tt>test</tt> argument has the following methods:
 
<tt>test.'''pass'''([''message''])</tt>
 
Marks a test as passing, with the given optional message.
 
<tt>test.'''fail'''([''message''])</tt>
 
Marks a test as failing, with the given optional message.
 
<tt>test.'''exception'''(''e'')</tt>
 
Marks a test as failing due to the given exception having been thrown.  This can be put in a <tt>catch</tt> clause.
 
<tt>test.'''assertEqual'''(''a'', ''b''[, ''message''])</tt>
 
Simply ensures that ''a'' <tt>==</tt> ''b'' without recursing into ''a'' or ''b''.  A test is marked as passing or failing depending on the result, logging ''message'' with it.
 
<tt>test.'''assertNotEqual'''(''a'', ''b''[, ''message''])</tt>
 
Simply ensures that ''a'' <tt>!=</tt> ''b'' without recursing into ''a'' or ''b''.  A test is marked as passing or failing depending on the result, logging ''message'' with it.
 
<tt>test.'''assertMatches'''(''string'', ''regexp''[, ''message''])</tt>
 
Ensures that the given string matches the given regular expression.  If it does, marks a test as passing, otherwise marks a test as failing.  ''message'' is logged with the pass or fail.
 
<tt>test.'''assertRaises'''(''func'', ''predicate''[, ''message''])</tt>
 
Calls the function ''func'' with no arguments, expecting an exception to be raised. If nothing is raised, marks the test as failing. If an exception is raised, the exception's <tt>message</tt> property is compared with ''predicate'': if ''predicate'' is a string, then a simple equality comparison is done with <tt>message</tt>. Otherwise, if ''predicate'' is a regular expression, <tt>message</tt> is tested against it. Depending on the outcome, a test is marked as passing or failing, and ''message'' is logged.
 
<tt>test.'''waitUntilDone'''([''timeout''])</tt>
 
Puts the test runner into asynchronous testing mode, waiting up to ''timeout'' milliseconds for <tt>test.done()</tt> to be called.  This is intended for use in situations where a test suite schedules a callback, calls <tt>test.waitUntilDone</tt>, and then calls <tt>test.done()</tt> in the callback.
 
<tt>test.'''done'''()</tt>
 
Marks a test as being complete.  Assumes a previous call to <tt>test.waitUntilDone()</tt>.


==== Program Modules ====
==== Program Modules ====
874

edits

Navigation menu