diff --git a/lib/function_inheritance.js b/lib/function_inheritance.js index 1c1b0f9..3f200d9 100644 --- a/lib/function_inheritance.js +++ b/lib/function_inheritance.js @@ -1047,7 +1047,7 @@ defClassMethod(function getDescendantsDict(constructor) { } namespace = child.namespace; - + // Add extra identifier info if this child comes from another namespace if (namespace != parent_namespace) { if (namespace.startsWith(parent_namespace)) { diff --git a/test/function_inheritance.js b/test/function_inheritance.js index a20498f..189e6c4 100644 --- a/test/function_inheritance.js +++ b/test/function_inheritance.js @@ -1061,6 +1061,59 @@ describe('Inheritance', function() { }); }); + describe('#getDescendants()', () => { + it('should return all the descendants of a class as an array', () => { + + const RootRole = Function.inherits('Informer', 'RootRole'); + + RootRole.postInherit(function afterInherit() { + // A type_name or type_path is required, + // and this is actually not (yet) automatically set by Protoblast + this.type_name = this.name.underscore(); + }); + + const RootRoleChild = Function.inherits('RootRole', 'RootRoleChild'); + const RootRoleSecondChild = Function.inherits('RootRole', 'RootRoleSecondChild'); + const RootRoleGrandChild = Function.inherits('RootRoleChild', 'RootRoleGrandChild'); + + let children = RootRole.getDescendants(); + assert.strictEqual(children.length, 3); + }); + + it('should do the same for classes in a namespace', () => { + + const NsRole = Function.inherits('RootRole', 'Nested', 'NestedRole'); + const NestedChild = Function.inherits('Nested.NestedRole', 'NestedChild'); + const NestedGrandChild = Function.inherits('Nested.NestedChild', 'NestedGrandChild'); + + let children = NsRole.getDescendants(); + assert.strictEqual(children.length, 2); + + let root_children = Blast.Classes.RootRole.getDescendants(); + assert.strictEqual(root_children.length, 6); + }); + }); + + describe('#getDescendantsDict()', () => { + it('should return all the descendants in an Object dictionary', () => { + + let children = Blast.Classes.RootRole.getDescendantsDict(); + + let keys = Object.keys(children); + + assert.strictEqual(keys.length, 6); + + assert.deepStrictEqual(keys, [ + 'root_role_child', + 'root_role_grand_child', + 'root_role_second_child', + 'nested.nested_role', + 'nested.nested_child', + 'nested.nested_grand_child' + ]); + }); + }); + describe('#setProperty(getter)', function() { var Alpha, diff --git a/test/pledge.js b/test/pledge.js index c14f3bc..3dec4c2 100644 --- a/test/pledge.js +++ b/test/pledge.js @@ -996,6 +996,66 @@ describe('Swift', function() { assert.strictEqual(result, 42); }); + + it('should always return errors using a pledge', async () => { + + let result = Pledge.Swift.waterfall( + 47, + val => { + throw new Error('Sync error!'); + } + ); + + assert.strictEqual(result instanceof Pledge, true); + + let error; + + try { + await result; + } catch (err) { + error = err; + } + + assert.strictEqual(error.message, 'Sync error!'); + + result = Pledge.Swift.waterfall( + 47, + val => { + let pledge = new Pledge.Swift(); + pledge.reject(new Error('Sync rejection!')); + return pledge; + } + ); + + assert.strictEqual(result instanceof Pledge, true); + + try { + await result; + } catch (err) { + error = err; + } + + assert.strictEqual(error.message, 'Sync rejection!'); + + result = Pledge.Swift.waterfall( + 47, + val => { + let pledge = new Pledge.Swift(); + setTimeout(() => pledge.reject(new Error('Async rejection!')), 1); + return pledge; + } + ); + + assert.strictEqual(result instanceof Pledge, true); + + try { + await result; + } catch (err) { + error = err; + } + + assert.strictEqual(error.message, 'Async rejection!'); + }); }); describe('#cancel()', () => {