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.

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

mercurial