aboutsummaryrefslogtreecommitdiff
path: root/tools/addon-sdk-1.3/packages/api-utils/docs/unit-test.md
blob: 401b551031f7bc83e37d81a55785d11a90c376ce (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
<!-- contributed by Atul Varma [atul@mozilla.com]  -->
<!-- edited by Noelle Murata [fiveinchpixie@gmail.com]  -->
<!-- edited by Shane Tomlinson[stomlinson@mozilla.com] -->

The `unit-test` module makes it easy to find and run unit tests.

<api name="test">
@class
Each function which represents a test case is passed a single argument
`test`, which represents the test runner.

<api name="pass">
@method
  Marks a test as passing, with the given optional message.

@param [message] {string}
  Optional passing message.
</api>


<api name="fail">
@method
  Marks a test as failing, with the given optional message.

@param [message] {string}
  Optional failure message.
</api>

<api name="expectFail">
@method
  *experimental* Expect the test enclosed within `func` to fail. 

@param func {function}
  A function that should contain a test that is expected to fail.
</api>

<api name="exception">
@method
  Marks a test as failing due to the given exception having been thrown.
  This can be put in a `catch` clause.

@param e {exception}
  An exception.
</api>

<api name="assert">
@method
  Ensures that `a` has a truthy value.

@param a {value}
  Value to verify.
@param [message] {string}
  The test is marked as passing or failing depending on the result, logging
  *message* with it.
</api>


<api name="assertEqual">
@method
  Ensures that `a == b` without recursing into `a` or `b`.

@param a {value}
  A value.

@param b {value}
  Another value.

@param [message] {string}
  The test is marked as passing or failing depending on the result, logging
  *message* with it.
</api>

<api name="assertNotEqual">
@method
  Ensures that `a != b` without recursing into `a` or `b`.

@param a {value}
  A value.

@param b {value}
  Another value.

@param [message] {string}
  The test is marked as passing or failing depending on the result, logging
  *message* with it.
</api>

<api name="assertStrictEqual">
@method
  Ensures that `a === b` without recursing into `a` or `b`.

@param a {value}
  A value.

@param b {value}
  Another value.

@param [message] {string}
  The test is marked as passing or failing depending on the result, logging
  *message* with it.
</api>


<api name="assertNotStrictEqual">
@method
  Ensures that `a !== b` without recursing into `a` or `b`.

@param a {value}
  A value.

@param b {value}
  Another value.

@param [message] {string}
  The test is marked as passing or failing depending on the result, logging
  *message* with it.
</api>

<api name="assertMatches">
@method
  Ensures that the given string matches the given regular expression.
  If it does, marks a test as passing, otherwise marks a test as
  failing.

@param string {string}
  The string to test.

@param regexp {regexp}
  The string should match this regular expression.

@param [message] {string}
  The test is marked as passing or failing depending on the result, logging
  *message* with it.
</api>


<api name="assertRaises">
@method
  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 `message` property is
  compared with `predicate`: if `predicate` is a string, then a
  simple equality comparison is done with `message`. Otherwise,
  if `predicate` is a regular expression, `message` is tested
  against it.

@param func {function}
  A function that should raise an exception when called.

@param predicate {string,regexp}
  A string or regular expression to compare to the exception's message.

@param [message] {string}
  Depending on the outcome, a test is marked as passing or failing, and
  *message* is logged.
</api>


<api name="assertFunction">
@method
  Ensures that `a` is a function.

@param a {value}
  A value.

@param [message] {string}
  The test is marked as passing or failing depending on the result, logging
  *message* with it.
  
</api>  


<api name="assertUndefined">
@method
  Ensures that `a` is `undefined`.  `null`, `0`, and `false` will all fail.

@param a {value}
  A value.

@param [message] {string}
  The test is marked as passing or failing depending on the result, logging
  *message* with it.
  
</api>  


<api name="assertNotUndefined">
@method
  Ensures that `a` is not `undefined`.  `null`, `0`, and `false` will all pass.

@param a {value}
  A value.

@param [message] {string}
  The test is marked as passing or failing depending on the result, logging
  *message* with it.
  
</api>  


<api name="assertNull">
@method
  Ensures that `a` is `null`.  `undefined`, `0`, and `false` will all fail.

@param a {value}
  A value.

@param [message] {string}
  The test is marked as passing or failing depending on the result, logging
  *message* with it.
  
</api>  


<api name="assertNotNull">
@method
  Ensures that `a` is not `null`.  `undefined`, `0`, and `false` will all pass.

@param a {value}
  A value.

@param [message] {string}
  The test is marked as passing or failing depending on the result, logging
  *message* with it.
  
</api>  


<api name="assertObject">
@method
  Ensures that `a` is an object.  A function, string, or number will fail.

@param a {value}
  A value.

@param [message] {string}
  The test is marked as passing or failing depending on the result, logging
  *message* with it.
  
</api>  


<api name="assertString">
@method
  Ensures that `a` is a string.

@param a {value}
  A value.

@param [message] {string}
  The test is marked as passing or failing depending on the result, logging
  *message* with it.
  
</api>  


<api name="assertArray">
@method
  Ensures that `a` is an array.

@param a {value}
  A value.

@param [message] {string}
  The test is marked as passing or failing depending on the result, logging
  *message* with it.
  
</api>  


<api name="assertNumber">
@method
  Ensures that `a` is a number.

@param a {value}
  A value.

@param [message] {string}
  The test is marked as passing or failing depending on the result, logging
  *message* with it.
  
</api>  


<api name="waitUntilDone">
@method
  Puts the test runner into asynchronous testing mode, waiting up to
  *timeout* milliseconds for `test.done()` to be called.  This
  is intended for use in situations where a test suite schedules a
  callback, calls `test.waitUntilDone()`, and then calls
  `test.done()` in the callback.

@param [timeout] {integer}
  If this number of milliseconds elapses and `test.done()` has not yet been
  called, the test is marked as failing.
</api>


<api name="done">
@method
  Marks a test as being complete.  Assumes a previous call to
  `test.waitUntilDone()`.
</api>

</api>


<api name="waitUntil">
@method
  Ensures that `a` returns a truthy value within a reasonable amount of time.

@param a {function}
  Function that returns the value to verify.
@param [message] {string}
  The test is marked as passing or failing depending on the result, logging
  *message* with it.
</api>


<api name="waitUntilEqual">
@method
  Ensures that `a == b` returned values or values without without recursing
  into `a` or `b`.

@param a {Function}
  A value, or a function that returns a value.

@param b {value}
  Another value, or a function that returns value.

@param [message] {string}
  The test is marked as passing or failing depending on the result, logging
  *message* with it.
</api>

<api name="waitUntilNotEqual">
@method
  Ensures that `a != b` without recursing into `a` or `b`.

@param a {Function}
  A value, or a function that returns a value.

@param b {value}
  Another value, or a function that returns another value.

@param [message] {string}
  The test is marked as passing or failing depending on the result, logging
  *message* with it.
</api>


<api name="waitUntilMatches">
@method
  Ensures that the given string matches the given regular expression.
  If it does, marks the test as passing, otherwise marks the test as
  failing.

@param string {Function}
  A function that returns the string to test.

@param regexp {regexp}
  The string should match this regular expression.

@param [message] {string}
  The test is marked as passing or failing depending on the result, logging
  *message* with it.
</api>



<api name="findAndRunTests">
@function
  The list of directories is searched for SecurableModules that start
  with the prefix `test-`.  Each module matching this criteria is
  expected to export functions that are test cases or a suite of test
  cases; each is called with a single argument, which is a Test Runner
  Object.

@param options {object}
  An object with the following properties:
  @prop dirs {string}
    A list of absolute paths representing directories to search
    for tests in.  It's assumed that all of these directories are also
    in the module search path, i.e. any JS files found in them are
    SecurableModules that can be loaded via a call to
    `require()`.
  @prop onDone {function}
    A function to call when testing is complete.
</api>