diff --git a/lib/_lg-clone-all-before.js b/lib/_lg-clone-all-before.js new file mode 100644 index 00000000..c0764738 --- /dev/null +++ b/lib/_lg-clone-all-before.js @@ -0,0 +1,22 @@ +/** + * Performs the "cloneBefore" method for each key/value pair given + * + * @param {object} props - Key/Value pairs for each CloneBefore + * @param {Declaration} decl - The PostCSS Declaration + * + * @example + * + * cloneAllBefore({ + * 'margin-left': '0 !important', + * 'margin-right': lostOffsetGutter + ' !important', + * declaration + * }); + */ +module.exports = function lgCloneAllBefore(props, decl) { + Object.keys(props).forEach(function traverseProps(prop) { + decl.cloneBefore({ + prop: prop, + value: props[prop] + }); + }); +}; diff --git a/lib/_lg-clone-all-before.spec.js b/lib/_lg-clone-all-before.spec.js new file mode 100644 index 00000000..15aba10d --- /dev/null +++ b/lib/_lg-clone-all-before.spec.js @@ -0,0 +1,30 @@ +/* globals describe, require, it, beforeEach */ + +'use strict'; + +var chai = require('chai'); +var sinon = require('sinon'); +var sinonChai = require('sinon-chai'); +var expect = chai.expect; + +var lgCloneAllBefore = require('./_lg-clone-all-before'); + +chai.use(sinonChai); + +describe('lgCloneAllBefore', function () { + var decl = {}; + + beforeEach(function () { + decl.cloneBefore = function () {}; + }); + + it('calls "cloneBefore" correctly', function () { + decl.cloneBefore = sinon.spy(); + lgCloneAllBefore({'margin-left': '0'}, decl); + expect(decl.cloneBefore) + .to.have.been.calledWith({ + prop: 'margin-left', + value: '0', + }); + }); +});