michael@0: /* This Source Code Form is subject to the terms of the Mozilla Public michael@0: * License, v. 2.0. If a copy of the MPL was not distributed with this michael@0: * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ michael@0: michael@0: "use strict"; michael@0: michael@0: const AssertBase = require("sdk/test/assert").Assert; michael@0: michael@0: /** michael@0: * Generates custom assertion constructors that may be bundled with a test michael@0: * suite. michael@0: * @params {String} michael@0: * names of assertion function to be added to the generated Assert. michael@0: */ michael@0: function Assert() { michael@0: let assertDescriptor = {}; michael@0: Array.forEach(arguments, function(name) { michael@0: assertDescriptor[name] = { value: function(message) { michael@0: this.pass(message); michael@0: }} michael@0: }); michael@0: michael@0: return function Assert() { michael@0: return Object.create(AssertBase.apply(null, arguments), assertDescriptor); michael@0: }; michael@0: } michael@0: michael@0: exports["test suite"] = { michael@0: Assert: Assert("foo"), michael@0: "test that custom assertor is passed to test function": function(assert) { michael@0: assert.ok("foo" in assert, "custom assertion function `foo` is defined"); michael@0: assert.foo("custom assertion function `foo` is called"); michael@0: }, michael@0: "test sub suite": { michael@0: "test that `Assert` is inherited by sub suits": function(assert) { michael@0: assert.ok("foo" in assert, "assertion function `foo` is not defined"); michael@0: }, michael@0: "test sub sub suite": { michael@0: Assert: Assert("bar"), michael@0: "test that custom assertor is passed to test function": function(assert) { michael@0: assert.ok("bar" in assert, michael@0: "custom assertion function `bar` is defined"); michael@0: assert.bar("custom assertion function `bar` is called"); michael@0: }, michael@0: "test that `Assert` is not inherited by sub sub suits": function(assert) { michael@0: assert.ok(!("foo" in assert), michael@0: "assertion function `foo` is not defined"); michael@0: } michael@0: } michael@0: } michael@0: }; michael@0: michael@0: if (module == require.main) michael@0: require("test").run(exports);