Skip to content

Commit

Permalink
Add tests to stylePropToObj plugin
Browse files Browse the repository at this point in the history
  • Loading branch information
Yeti-or committed Apr 19, 2017
1 parent 303b573 commit a52bd8a
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 6 deletions.
7 changes: 5 additions & 2 deletions lib/plugins.js
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,11 @@ module.exports.defaultPlugins = [
});
},
function stylePropToObj(jsx) {
jsx.props['style'] &&
(jsx.props['attrs']['style'] = jsx.props['style'] = styleToObj(jsx.props['style']));
if (jsx.props['style']) {
jsx.props['style'] = styleToObj(jsx.props['style'])
jsx.props['attrs'] &&
(jsx.props['attrs']['style'] = jsx.props['style']);
}
}
];

Expand Down
24 changes: 20 additions & 4 deletions test/plugins.js
Original file line number Diff line number Diff line change
@@ -1,16 +1,14 @@
const expect = require('chai').expect;

var T = require('../lib');
var transformer = T();

var BemEntity = require('@bem/entity-name');
// var transform = transformer.process.bind(transformer);

describe('pluginis', () => {

describe('whiteList', () => {
it('without opts', () => {
var res = transformer
var res = T()
.use(T.plugins.whiteList())
.process({ block: 'button2' });

Expand All @@ -20,7 +18,7 @@ describe('pluginis', () => {
});

it('whiteList', () => {
var res = transformer
var res = T()
.use(T.plugins.whiteList({ entities: [{ block: 'button2' }].map(BemEntity.create) }))
.process({ block: 'button2', content: [{ block: 'menu' }, { block: 'selec' }] });

Expand All @@ -30,4 +28,22 @@ describe('pluginis', () => {
});
});

describe('stylePropToObj', () => {
it('styleProp to obj', () => {
var res = T().process({ block: 'button2', style: 'width:200px' });

expect(res.JSX).to.equal(
`<Button2 style={{ 'width': '200px' }}/>`
);
});

it('attrs style to obj', () => {
var res = T().process({ block: 'button2', attrs: { style: 'width:200px' } });

expect(res.JSX).to.equal(
`<Button2 style={{ 'width': '200px' }} attrs={{ 'style': { 'width': '200px' } }}/>`
);
});
});

});

0 comments on commit a52bd8a

Please sign in to comment.