diff options
| author | Michael Williamson <mike@zwobble.org> | 2016-11-20 12:15:39 +0000 |
|---|---|---|
| committer | Michael Williamson <mike@zwobble.org> | 2016-11-20 12:16:49 +0000 |
| commit | e09b1f797d646e240e405831a9ddccd21ca4b3f9 (patch) | |
| tree | 4f5fd0a872457d5aab7c6882e43485ac076d9d6e /test | |
| parent | f4a6e9f3077e009ce36d03ff9fb704dc8bcff31b (diff) | |
Add getDescendants and getDescendantsOfType to tranforms
Diffstat (limited to 'test')
| -rw-r--r-- | test/transforms.tests.js | 50 |
1 files changed, 50 insertions, 0 deletions
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] + ); + } +}); |
