Skip to content

Commit

Permalink
Merge pull request #482 from unexpectedjs/ssimonsen/relax-style-valid…
Browse files Browse the repository at this point in the history
…ation

Relax style validation
  • Loading branch information
sunesimonsen authored Nov 28, 2023
2 parents 5f2ed4f + 7ff18f7 commit 70be405
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 24 deletions.
5 changes: 1 addition & 4 deletions src/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -86,10 +86,7 @@ function isEnumeratedAttribute(attrName) {
function validateStyles(expect, str) {
const invalidStyles = str
.split(';')
.filter(
(part) =>
!/^\s*(\w|-)+\s*:\s*(#(?:[0-9a-fA-F]{3}){1,2}|[^#]+)\s*$|^$/.test(part)
);
.filter((part) => !/^\s*(\w|-)+\s*:\s*|^\s*$/.test(part));

if (invalidStyles.length > 0) {
expect.errorMode = 'nested';
Expand Down
26 changes: 6 additions & 20 deletions test/assertions/to-satisfy.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -804,27 +804,13 @@ describe('"to satisfy" assertion', () => {
);
});

it.skipIf(isIe, 'should fail when the RHS has invalid styles', () =>
it('should not fail for a shorthand style attribute on the RHS', () => {
expect(
() =>
expect(
parseHtml('<div style="border-left-color: #FFF">hey</div>'),
'to satisfy',
parseHtml('<div style="border-left-color: #FFFF;">hey</div>')
),
'to throw an error satisfying to equal snapshot',
expect.unindent`
expected <div style="border-left-color: #FFF">hey</div>
to satisfy <div style="border-left-color: #FFFF">hey</div>
<div
style="border-left-color: #FFF" // expected <div style="border-left-color: #FFF">hey</div>
// to satisfy { name: 'div', attributes: { style: 'border-left-color: #FFFF;' }, children: [ hey ] }
// Expectation contains invalid styles: 'border-left-color: #FFFF'
>hey</div>
`
)
);
parseHtml('<div style="border: 2px dashed #960FD4;">hey</div>'),
'to satisfy',
parseHtml('<div style="border: 2px dashed #960FD4;">hey</div>')
);
});

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

0 comments on commit 70be405

Please sign in to comment.