Commit a00a7eb4 authored by Daniel Shumway's avatar Daniel Shumway

test: improve test coverage for `then`

- add context tests for `test`
parent 7cd0758d
Pipeline #8412425 passed with stage
in 53 seconds
......@@ -145,7 +145,7 @@ suite.test('Exceptions from functions within promises (#9)', function () {
});
function assertion () {
assert.strictEqual(_a.status, Distilled.STATUS.FAILED, 'Exceptiosn from recursively called functions are caught correctly');
assert.strictEqual(_a.status, Distilled.STATUS.FAILED, 'Exceptions from recursively called functions are caught correctly');
}
return def.promise;
......
......@@ -31,7 +31,6 @@ suite.test('Tests/suites expose a `test` method', function () {
/*
* Distilled is designed to be extended, so if you extend Distilled, new tests will correctly inherit from your prototype.
* They'll also call custom constructors if you define them on the prototype.
*/
this.test('also works when extending prototype', function () {
function Extension () {
......@@ -46,6 +45,21 @@ suite.test('Tests/suites expose a `test` method', function () {
});
});
suite.test('Tests expose their children:', function () {
var that = this;
var _suite = new Distilled(function () {});
var def = deferred();
var _child = _suite.test('', function (_test) {
that.test('as a parameter', _test === _child);
that.test('as the context', this === _child);
def.resolve();
});
return def.promise;
});
/*
* Returning promises and taking advantage of recursively resolving test results:
* - this allows you to separate your setup logic and your testing logic, improving readability.
......
......@@ -26,12 +26,27 @@ function deferred () {
suite = suite.test('Tests/suites expose a `then` method', function () {
var _suite = new Distilled(function () {});
assert.strictEqual(typeof suite.then, 'function');
assert.strictEqual(typeof _suite.then, 'function');
this.test('Calling `then` returns the same test/suite', function () {
assert.strictEqual(_suite, _suite.then());
});
});
suite.test('`then` exposes the suite:', function () {
var that = this;
var _suite = new Distilled(function () {});
var def = deferred();
_suite.then(function (_test) {
that.test('as a parameter', _test === _suite);
that.test('as the context', this === _suite);
def.resolve();
});
return def.promise;
});
suite.test('`then` is called when a test finishes.', function (test) {
var def = deferred();
var _suite = new Distilled(function () {});
......
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