Commit 42214d54 authored by Daniel Shumway's avatar Daniel Shumway

feat: `test` always attaches to the right prototype

- addresses issue #11
parent faf4c406
Pipeline #5191284 passed with stage
in 1 minute and 9 seconds
......@@ -77,7 +77,7 @@ var Suite = (function () {
options = options || {};
var that = this;
var _that = this[PRIVATE] = {
__proto__ : this.constructor._prototype, //TODO: how many browsers do I lock out with this? Do I care?
__proto__ : Suite._prototype, //TODO: how many browsers do I lock out with this? Do I care?
promise : options.promise || Promise.resolve(), //Group will run tests once parent promise has resolved
callback : options.callback || function () {},
......@@ -194,7 +194,8 @@ var Suite = (function () {
throw error;
});
suite = new Suite({
suite = Object.create(that.constructor.prototype);
Suite.call(suite, {
label : message,
promise : promise,
parent : that,
......@@ -220,7 +221,9 @@ function Distilled(callback, options) {
});
}
Distilled.prototype = Suite.prototype;
Distilled.prototype = Object.create(Suite.prototype);
Distilled.prototype.constructor = Distilled;
Distilled.STATUS = STATUS;
Distilled.REPORTERS = REPORTERS;
......
......@@ -28,6 +28,17 @@ suite.test('Tests/suites expose a `test` method', function () {
assert.strictEqual(typeof suite.test, 'function');
this.test('Calling `test` returns a new test/suite of the same type', function () {
assert.strictEqual(Object.getPrototypeOf(_suite), Object.getPrototypeOf(_suite.test()));
this.test('also works when extending prototype', function () {
function Extension () {
Distilled.apply(this, arguments);
}
Extension.prototype = Object.create(Distilled.prototype);
Extension.prototype.constructor = Extension;
var _extension = new Extension(function () {});
assert.strictEqual(Object.getPrototypeOf(_extension), Object.getPrototypeOf(_extension.test()));
});
});
});
......
......@@ -10,7 +10,7 @@ var tape = require('tape');
var Distilled = require('Distilled');
tape('Tests/suites expose a `test` method', function (t) {
t.plan(2);
t.plan(3);
var suite = new Distilled(function () {});
......@@ -19,6 +19,17 @@ tape('Tests/suites expose a `test` method', function (t) {
//Use OK instead of `equal` because tape tries to incorrectly access prototype properties during the test
t.ok(Object.getPrototypeOf(suite) === Object.getPrototypeOf(suite.test('A')),
'Calling `test` returns a new test/suite of the same type');
//Also works when extending prototype
function Extension () {
Distilled.apply(this, arguments);
}
Extension.prototype = Object.create(Distilled.prototype);
Extension.prototype.constructor = Extension;
var _extension = new Extension(function () {});
t.ok(Object.getPrototypeOf(_extension) === Object.getPrototypeOf(_extension.test()),
'Calling `test` on an extended suite returns a new test/suite of the same type');
});
tape('Child tests/suites are chained off of their parents', function (t) {
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment