Skip to content

Commit

Permalink
Change the error mode of the when parsed as... adverbial assertions t…
Browse files Browse the repository at this point in the history
…o 'nested' so the output isn't swallowed.
  • Loading branch information
papandreou committed May 8, 2015
1 parent 443c0ac commit 5e4cf00
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 0 deletions.
2 changes: 2 additions & 0 deletions lib/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -716,6 +716,7 @@ module.exports = {
});

expect.addAssertion('string', 'when parsed as (html|HTML)', function (expect, subject) {
this.errorMode = 'nested';
var htmlDocument;
if (typeof DOMParser !== 'undefined') {
htmlDocument = new DOMParser().parseFromString(subject, 'text/html');
Expand All @@ -735,6 +736,7 @@ module.exports = {
});

expect.addAssertion('string', 'when parsed as (xml|XML)', function (expect, subject) {
this.errorMode = 'nested';
var xmlDocument;
if (typeof DOMParser !== 'undefined') {
xmlDocument = new DOMParser().parseFromString(subject, 'text/xml');
Expand Down
16 changes: 16 additions & 0 deletions test/unexpected-dom.js
Original file line number Diff line number Diff line change
Expand Up @@ -964,6 +964,22 @@ describe('unexpected-dom', function () {
);
});

it('should fail when the next assertion fails', function () {
expect(function () {
expect(htmlSrc, 'when parsed as HTML', 'queried for first', 'body', 'to have attributes', { class: 'quux' });
}, 'to throw',
'expected \'<!DOCTYPE html><html><body class="bar">foo</body></html>\'\n' +
'when parsed as HTML queried for first \'body\', \'to have attributes\', { class: \'quux\' }\n' +
' expected <!DOCTYPE html><html><head></head><body class="bar">...</body></html>\n' +
' queried for first \'body\' to have attributes { class: \'quux\' }\n' +
' expected <body class="bar">foo</body> to have attributes { class: \'quux\' }\n' +
'\n' +
' <body class="bar" // expected [ \'bar\' ] to contain \'quux\'\n' +
' >foo</body>'
);
});


describe('when the DOMParser global is available', function () {
var originalDOMParser,
DOMParserSpy,
Expand Down

0 comments on commit 5e4cf00

Please sign in to comment.