From 8c51a2f26b8d3b39ba0f933064a95f20ba4448ca Mon Sep 17 00:00:00 2001 From: Nico Rehwaldt Date: Thu, 4 Oct 2018 15:26:04 +0200 Subject: [PATCH] feat(project): add prepend utility --- lib/prepend.js | 18 ++++++++++++++++++ test/spec/prepend.js | 25 +++++++++++++++++++++++++ 2 files changed, 43 insertions(+) create mode 100644 lib/prepend.js create mode 100644 test/spec/prepend.js diff --git a/lib/prepend.js b/lib/prepend.js new file mode 100644 index 0000000..dbca8f5 --- /dev/null +++ b/lib/prepend.js @@ -0,0 +1,18 @@ +/** + * prepend utility + */ + +import prependTo from './prependTo'; + +/** + * Prepend a node to a target element + * + * @param {SVGElement} target + * @param {SVGElement} node + * + * @return {SVGElement} the target element + */ +export default function prepend(target, node) { + prependTo(node, target); + return target; +} \ No newline at end of file diff --git a/test/spec/prepend.js b/test/spec/prepend.js new file mode 100644 index 0000000..8ba6d43 --- /dev/null +++ b/test/spec/prepend.js @@ -0,0 +1,25 @@ +import { + create, + prepend +} from '../../lib'; + + +describe('prepend', function() { + + it('should prepend + return parent', function() { + + // given + var svg = create(''), + g = create(''); + + // when + var result = prepend(svg, g); + + // then + expect(result).to.exist; + + expect(svg.childNodes).to.have.length(2); + expect(svg.firstChild).to.equal(g); + }); + +}); \ No newline at end of file