Skip to content

Commit

Permalink
Handle missing className case in attribute comparison
Browse files Browse the repository at this point in the history
  • Loading branch information
Munter committed Jun 12, 2015
1 parent b92c344 commit ed6535a
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 0 deletions.
4 changes: 4 additions & 0 deletions lib/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,10 @@ function styleStringToObject(str) {
}

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

var classNames = attributeValue.split(/\s+/);
if (classNames.length === 1 && classNames[0] === '') {
classNames.pop();
Expand Down
8 changes: 8 additions & 0 deletions test/unexpected-dom.js
Original file line number Diff line number Diff line change
Expand Up @@ -208,6 +208,14 @@ describe('unexpected-dom', function () {
});

describe('to have class', function () {
it('should handle a non-existing class', function () {
body.innerHTML = '<button>Press me</button>';

expect(function () {
expect(body.firstChild, 'to have class', 'foo');
}, 'to throw', 'expected <button>Press me</button> to have class \'foo\'\n\n<button\n // missing class should satisfy \'foo\'\n>Press me</button>');
});

describe('with a single class passed as a string', function () {
it('should succeed', function () {
body.innerHTML = '<button id="foo" class="bar" data-info="baz" disabled>Press me</button>';
Expand Down

0 comments on commit ed6535a

Please sign in to comment.