Skip to content

Commit

Permalink
fix(parser): do not add to output if css value is empty
Browse files Browse the repository at this point in the history
Update tests with invalid and error cases.
  • Loading branch information
remarkablemark committed Nov 17, 2017
1 parent d7e0450 commit 0759da7
Show file tree
Hide file tree
Showing 3 changed files with 28 additions and 4 deletions.
5 changes: 4 additions & 1 deletion index.js
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,10 @@ module.exports = function parseInlineStyleServer(style) {
var output = {};

declarations.forEach(function(declaration) {
output[declaration.property] = declaration.value;
var value = declaration.value;
if (value) {
output[declaration.property] = value;
}
});

return output;
Expand Down
12 changes: 12 additions & 0 deletions test/cases.js
Original file line number Diff line number Diff line change
Expand Up @@ -97,6 +97,18 @@ const styles = [
display: 'flex',
},
},

// missing value
{
style: 'z-index:',
expected: {},
},

// missing property
{
style: ': 42',
expected: Error,
},
];

module.exports = {
Expand Down
15 changes: 12 additions & 3 deletions test/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,19 @@ const parser = require('../')

describe('parser', () => {
cases.default.forEach(({ style, expected }) => {

describe(`when style=\`${style}\``, () => {
it(`returns ${JSON.stringify(expected)}`, () => {
assert.deepEqual(parser(style), expected);
});
if (expected === Error) {
it('throws error', () => {
assert.throws(() => parser(style), Error);
});

} else {
it(`returns ${JSON.stringify(expected)}`, () => {
assert.deepEqual(parser(style), expected);
});
}
});

});
});

0 comments on commit 0759da7

Please sign in to comment.