addon-sdk/source/test/commonjs-test-adapter/asserts.js

Wed, 31 Dec 2014 06:09:35 +0100

author
Michael Schloh von Bennewitz <michael@schloh.com>
date
Wed, 31 Dec 2014 06:09:35 +0100
changeset 0
6474c204b198
permissions
-rw-r--r--

Cloned upstream origin tor-browser at tor-browser-31.3.0esr-4.5-1-build1
revision ID fc1c9ff7c1b2defdbc039f12214767608f46423f for hacking purpose.

     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/. */
     5 "use strict";
     7 const AssertBase = require("sdk/test/assert").Assert;
     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   });
    23   return function Assert() {
    24     return Object.create(AssertBase.apply(null, arguments), assertDescriptor);
    25   };
    26 }
    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 };
    53 if (module == require.main)
    54   require("test").run(exports);

mercurial