Skip to content

Commit

Permalink
#382 Makes 'cloneAllBefore' a reusable method
Browse files Browse the repository at this point in the history
  • Loading branch information
peterramsing committed Apr 7, 2018
1 parent b4ac707 commit 13dc038
Show file tree
Hide file tree
Showing 2 changed files with 52 additions and 0 deletions.
22 changes: 22 additions & 0 deletions lib/_lg-clone-all-before.js
Original file line number Diff line number Diff line change
@@ -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]
});
});
};
30 changes: 30 additions & 0 deletions lib/_lg-clone-all-before.spec.js
Original file line number Diff line number Diff line change
@@ -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',
});
});
});

0 comments on commit 13dc038

Please sign in to comment.