Skip to content

Commit

Permalink
feat(project): add prepend utility
Browse files Browse the repository at this point in the history
  • Loading branch information
nikku committed Oct 4, 2018
1 parent d6f3f59 commit 8c51a2f
Show file tree
Hide file tree
Showing 2 changed files with 43 additions and 0 deletions.
18 changes: 18 additions & 0 deletions lib/prepend.js
Original file line number Diff line number Diff line change
@@ -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;
}
25 changes: 25 additions & 0 deletions test/spec/prepend.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
import {
create,
prepend
} from '../../lib';


describe('prepend', function() {

it('should prepend + return parent', function() {

// given
var svg = create('<svg><g></g></svg>'),
g = create('<g id="G" />');

// when
var result = prepend(svg, g);

// then
expect(result).to.exist;

expect(svg.childNodes).to.have.length(2);
expect(svg.firstChild).to.equal(g);
});

});

0 comments on commit 8c51a2f

Please sign in to comment.