Skip to content

Commit ed6535a

Browse files
committed
Handle missing className case in attribute comparison
1 parent b92c344 commit ed6535a

File tree

2 files changed

+12
-0
lines changed

2 files changed

+12
-0
lines changed

lib/index.js

+4
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,10 @@ function styleStringToObject(str) {
3737
}
3838

3939
function getClassNamesFromAttributeValue(attributeValue) {
40+
if (attributeValue === null) {
41+
return '';
42+
}
43+
4044
var classNames = attributeValue.split(/\s+/);
4145
if (classNames.length === 1 && classNames[0] === '') {
4246
classNames.pop();

test/unexpected-dom.js

+8
Original file line numberDiff line numberDiff line change
@@ -208,6 +208,14 @@ describe('unexpected-dom', function () {
208208
});
209209

210210
describe('to have class', function () {
211+
it('should handle a non-existing class', function () {
212+
body.innerHTML = '<button>Press me</button>';
213+
214+
expect(function () {
215+
expect(body.firstChild, 'to have class', 'foo');
216+
}, 'to throw', 'expected <button>Press me</button> to have class \'foo\'\n\n<button\n // missing class should satisfy \'foo\'\n>Press me</button>');
217+
});
218+
211219
describe('with a single class passed as a string', function () {
212220
it('should succeed', function () {
213221
body.innerHTML = '<button id="foo" class="bar" data-info="baz" disabled>Press me</button>';

0 commit comments

Comments
 (0)