From e09b1f797d646e240e405831a9ddccd21ca4b3f9 Mon Sep 17 00:00:00 2001 From: Michael Williamson Date: Sun, 20 Nov 2016 12:15:39 +0000 Subject: Add getDescendants and getDescendantsOfType to tranforms --- test/transforms.tests.js | 50 ++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 50 insertions(+) create mode 100644 test/transforms.tests.js (limited to 'test/transforms.tests.js') diff --git a/test/transforms.tests.js b/test/transforms.tests.js new file mode 100644 index 0000000..c6656dd --- /dev/null +++ b/test/transforms.tests.js @@ -0,0 +1,50 @@ +var assert = require("assert"); + +var transforms = require("../lib/transforms"); +var test = require("./test")(module); + + +test("getDescendants()", { + "returns nothing if element has no children property": function() { + assert.deepEqual(transforms.getDescendants({}), []); + }, + + "returns nothing if element has empty children": function() { + assert.deepEqual(transforms.getDescendants({children: []}), []); + }, + + "includes children": function() { + var element = { + children: [{name: "child 1"}, {name: "child 2"}] + } + assert.deepEqual( + transforms.getDescendants(element), + [{name: "child 1"}, {name: "child 2"}] + ); + }, + + "includes indirect descendants": function() { + var grandchild = {name: "grandchild"}; + var child = {name: "child", children: [grandchild]}; + var element = {children: [child]}; + assert.deepEqual( + transforms.getDescendants(element), + [grandchild, child] + ); + } +}); + + +test("getDescendantsOfType()", { + "filters descendants to type": function() { + var paragraph = {type: "paragraph"}; + var run = {type: "run"}; + var element = { + children: [paragraph, run] + }; + assert.deepEqual( + transforms.getDescendantsOfType(element, "run"), + [run] + ); + } +}); -- cgit v1.2.3