Skip to content

Commit

Permalink
Merge 4d1e8eb into 3162a51
Browse files Browse the repository at this point in the history
  • Loading branch information
alexjeffburke authored Jun 7, 2019
2 parents 3162a51 + 4d1e8eb commit 269c7b4
Show file tree
Hide file tree
Showing 2 changed files with 58 additions and 0 deletions.
20 changes: 20 additions & 0 deletions src/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -724,6 +724,26 @@ module.exports = {
})
);

expect.exportAssertion(
'<DOMElement> not to have (class|classes) <array|string>',
(expect, subject, value) => {
return expect(subject, 'to have attributes', {
class: expect.it(className => {
const actualClasses = getClassNamesFromAttributeValue(className);
let expectedClasses;
if (typeof value === 'string') {
expectedClasses = getClassNamesFromAttributeValue(value);
} else {
expectedClasses = value;
}
return bubbleError(() =>
expect(actualClasses, 'not to contain', ...expectedClasses)
);
})
});
}
);

expect.exportAssertion(
'<DOMTextNode> to [exhaustively] satisfy <DOMTextNode>',
(expect, subject, value) =>
Expand Down
38 changes: 38 additions & 0 deletions test/index.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -446,6 +446,44 @@ describe('unexpected-dom', () => {
});
});

describe('with the "not" flag', () => {
describe('with a single class passed as a string', () => {
it('should succeed', () => {
body.innerHTML =
'<button disabled class="bar" id="foo" data-info="baz">Press me</button>';
expect(body.firstChild, 'not to have class', 'foo');
});

it('should fail with a diff', () => {
body.innerHTML =
'<button disabled class="bar quux" id="foo" data-info="baz">Press me</button>';
expect(
() => {
expect(body.firstChild, 'not to have class', 'quux');
},
'to throw',
'expected\n' +
'<button disabled class="bar quux" id="foo" data-info="baz">\n' +
' Press me\n' +
'</button>\n' +
"not to have class 'quux'\n" +
'\n' +
'<button\n' +
' disabled\n' +
" class=\"bar quux\" // expected [ 'bar', 'quux' ] not to contain 'quux'\n" +
' //\n' +
' // [\n' +
" // 'bar',\n" +
" // 'quux' // should be removed\n" +
' // ]\n' +
' id="foo"\n' +
' data-info="baz"\n' +
'>Press me</button>'
);
});
});
});

describe('with the "only" flag', () => {
describe('with a single class passed as a string', () => {
it('should succeed', () => {
Expand Down

0 comments on commit 269c7b4

Please sign in to comment.