|
1 /* This Source Code Form is subject to the terms of the Mozilla Public |
|
2 * License, v. 2.0. If a copy of the MPL was not distributed with this |
|
3 * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ |
|
4 |
|
5 "use strict"; |
|
6 |
|
7 const AssertBase = require("sdk/test/assert").Assert; |
|
8 |
|
9 /** |
|
10 * Generates custom assertion constructors that may be bundled with a test |
|
11 * suite. |
|
12 * @params {String} |
|
13 * names of assertion function to be added to the generated Assert. |
|
14 */ |
|
15 function Assert() { |
|
16 let assertDescriptor = {}; |
|
17 Array.forEach(arguments, function(name) { |
|
18 assertDescriptor[name] = { value: function(message) { |
|
19 this.pass(message); |
|
20 }} |
|
21 }); |
|
22 |
|
23 return function Assert() { |
|
24 return Object.create(AssertBase.apply(null, arguments), assertDescriptor); |
|
25 }; |
|
26 } |
|
27 |
|
28 exports["test suite"] = { |
|
29 Assert: Assert("foo"), |
|
30 "test that custom assertor is passed to test function": function(assert) { |
|
31 assert.ok("foo" in assert, "custom assertion function `foo` is defined"); |
|
32 assert.foo("custom assertion function `foo` is called"); |
|
33 }, |
|
34 "test sub suite": { |
|
35 "test that `Assert` is inherited by sub suits": function(assert) { |
|
36 assert.ok("foo" in assert, "assertion function `foo` is not defined"); |
|
37 }, |
|
38 "test sub sub suite": { |
|
39 Assert: Assert("bar"), |
|
40 "test that custom assertor is passed to test function": function(assert) { |
|
41 assert.ok("bar" in assert, |
|
42 "custom assertion function `bar` is defined"); |
|
43 assert.bar("custom assertion function `bar` is called"); |
|
44 }, |
|
45 "test that `Assert` is not inherited by sub sub suits": function(assert) { |
|
46 assert.ok(!("foo" in assert), |
|
47 "assertion function `foo` is not defined"); |
|
48 } |
|
49 } |
|
50 } |
|
51 }; |
|
52 |
|
53 if (module == require.main) |
|
54 require("test").run(exports); |