Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Allow style attributes with hex values. #247

Merged
merged 2 commits into from Jan 8, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
7 changes: 6 additions & 1 deletion src/index.js
Expand Up @@ -85,7 +85,12 @@ function isEnumeratedAttribute(attrName) {
function validateStyles(expect, str) {
const invalidStyles = str
.split(';')
.filter(part => !/^\s*(\w|-)+\s*:\s*(\w|-)+\s*$|^$/.test(part));
.filter(
part =>
!/^\s*(\w|-)+\s*:\s*(#(?:[0-9a-fA-F]{3}){1,2}|(\w|-)+)\s*$|^$/.test(
part
)
);

if (invalidStyles.length > 0) {
expect.errorMode = 'nested';
Expand Down
35 changes: 35 additions & 0 deletions test/index.spec.js
Expand Up @@ -1820,6 +1820,41 @@ describe('unexpected-dom', () => {
parseHtml('<div style="">hey</div>')
));

it('should not fail for a style attribute with hex value (short) on the RHS', () => {
expect(
parseHtml('<div style="border-left-color: #000">hey</div>'),
'to satisfy',
parseHtml('<div style="border-left-color: #000;">hey</div>')
);
});

it('should not fail for a style attribute with hex value (long) on the RHS', () => {
expect(
parseHtml('<div style="border-left-color: #1BcD3F">hey</div>'),
'to satisfy',
parseHtml('<div style="border-left-color: #1BcD3F;">hey</div>')
);
});

it('should fail when the RHS has invalid styles', () =>
expect(
() =>
expect(
parseHtml('<div style="border-left-color: #FFF">hey</div>'),
'to satisfy',
parseHtml('<div style="border-left-color: #FFFF;">hey</div>')
),
'to error',
'expected <div style="border-left-color: #FFF">hey</div>\n' +
'to satisfy <div style="border-left-color: #FFFF">hey</div>\n' +
'\n' +
'<div\n' +
' style="border-left-color: #FFF" // expected <div style="border-left-color: #FFF">hey</div>\n' +
" // to satisfy { name: 'div', attributes: { style: 'border-left-color: #FFFF;' }, children: [ 'hey' ] }\n" +
" // Expectation contains invalid styles: 'border-left-color: #FFFF'\n" +
'>hey</div>'
));

it('should fail when the RHS has invalid styles', () =>
expect(
() =>
Expand Down