-
-
Notifications
You must be signed in to change notification settings - Fork 161
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
#382 Makes 'cloneAllBefore' a reusable method
- Loading branch information
1 parent
b4ac707
commit 13dc038
Showing
2 changed files
with
52 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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] | ||
}); | ||
}); | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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', | ||
}); | ||
}); | ||
}); |