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

Ensure empty class attributes on both subject and value compare equal. #208

Merged
merged 1 commit into from
Sep 21, 2018
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.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 8 additions & 1 deletion lib/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -114,7 +114,11 @@ function styleStringToObject(str) {

function getClassNamesFromAttributeValue(attributeValue) {
if (attributeValue === null) {
return '';
return [];
}

if (attributeValue === '') {
return [];
}

var classNames = attributeValue.split(/\s+/);
Expand Down Expand Up @@ -1058,6 +1062,9 @@ module.exports = {
expectedClasses.sort()
);
} else {
if (expectedClasses.length === 0) {
return topLevelExpect(expectedClasses, 'to be empty');
}
return topLevelExpect.apply(
topLevelExpect,
[actualClasses, 'to contain'].concat(expectedClasses)
Expand Down
26 changes: 26 additions & 0 deletions test/index.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -1282,6 +1282,32 @@ describe('unexpected-dom', function() {
});
});

describe('when comparing class atttributes', function() {
it('should succeed when both are present but empty', function() {
expect(
'<div class="Component"><span class="foobar"></span><label><span class="">Some test stuff</span></label></div>',
'when parsed as HTML to satisfy',
'<div class="Component"><span class="foobar"></span><label><span class="">Some test stuff</span></label></div>'
);
});

it('should succeed when the RHS is absent and LHS has a value', function() {
expect(
'<div class="Component"><span></span><label><span class="foobar">Some test stuff</span></label></div>',
'when parsed as HTML to satisfy',
'<div class="Component"><span></span><label><span>Some test stuff</span></label></div>'
);
});

it('should succeed when the RHS is absent and LHS is empty', function() {
expect(
'<div class="Component"><span></span><label><span class="">Some test stuff</span></label></div>',
'when parsed as HTML to satisfy',
'<div class="Component"><span></span><label><span>Some test stuff</span></label></div>'
);
});
});

describe('HTMLFragment', function() {
describe('with a string as the value', function() {
it('should succeed', function() {
Expand Down