From 5e4cf0041cbbaa36d45966c6289f3c76d26de987 Mon Sep 17 00:00:00 2001 From: Andreas Lind Date: Sat, 9 May 2015 01:43:09 +0200 Subject: [PATCH] Change the error mode of the when parsed as... adverbial assertions to 'nested' so the output isn't swallowed. --- lib/index.js | 2 ++ test/unexpected-dom.js | 16 ++++++++++++++++ 2 files changed, 18 insertions(+) diff --git a/lib/index.js b/lib/index.js index 421fdd76..5af2e5d8 100644 --- a/lib/index.js +++ b/lib/index.js @@ -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'); @@ -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'); diff --git a/test/unexpected-dom.js b/test/unexpected-dom.js index c20a915f..2dc6ba60 100644 --- a/test/unexpected-dom.js +++ b/test/unexpected-dom.js @@ -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 \'foo\'\n' + + 'when parsed as HTML queried for first \'body\', \'to have attributes\', { class: \'quux\' }\n' + + ' expected ...\n' + + ' queried for first \'body\' to have attributes { class: \'quux\' }\n' + + ' expected foo to have attributes { class: \'quux\' }\n' + + '\n' + + ' foo' + ); + }); + + describe('when the DOMParser global is available', function () { var originalDOMParser, DOMParserSpy,