From 363458679bdb313f0343456af00c688393e18be4 Mon Sep 17 00:00:00 2001 From: Andreas Lind Date: Wed, 23 Dec 2015 13:22:55 +0100 Subject: [PATCH 1/5] Update unexpected to 10.5.0, adjust expected output. --- package.json | 2 +- test/unexpected-dom.js | 17 ++++++++++++----- 2 files changed, 13 insertions(+), 6 deletions(-) diff --git a/package.json b/package.json index f4e8868e..f9b950de 100644 --- a/package.json +++ b/package.json @@ -44,7 +44,7 @@ "mocha-lcov-reporter": "1.0.0", "sinon": "^1.15.4", "uglifyjs": "^2.4.10", - "unexpected": "10.0.2", + "unexpected": "10.5.0", "unexpected-sinon": "8.0.0" }, "dependencies": { diff --git a/test/unexpected-dom.js b/test/unexpected-dom.js index da586f3b..acbc9523 100644 --- a/test/unexpected-dom.js +++ b/test/unexpected-dom.js @@ -845,7 +845,7 @@ describe('unexpected-dom', function () { ' NodeList[\n' + '
\n' + ' foo // should satisfy { name: \'span\', attributes: {}, children: [ \'bar\' ] }\n' + - ' bar // should satisfy \'foo\'\n' + + ' bar // should satisfy foo\n' + '
\n' + ' ]' ); @@ -870,6 +870,7 @@ describe('unexpected-dom', function () { ' NodeList[\n' + '
\n' + ' foo // should equal \'quux\'\n' + + ' //\n' + ' // -foo\n' + ' // +quux\n' + '
,\n' + @@ -917,6 +918,7 @@ describe('unexpected-dom', function () { ' NodeList[\n' + '
\n' + ' foo // should equal \'quux\'\n' + + ' //\n' + ' // -foo\n' + ' // +quux\n' + '
,\n' + @@ -962,6 +964,7 @@ describe('unexpected-dom', function () { ' >foo,\n' + '
\n' + ' foobar // should equal \'bar\'\n' + + ' //\n' + ' // -foobar\n' + ' // +bar\n' + '
\n' + @@ -992,6 +995,7 @@ describe('unexpected-dom', function () { '
foo
,\n' + '
\n' + ' foobar // should equal \'bar\'\n' + + ' //\n' + ' // -foobar\n' + ' // +bar\n' + '
\n' + @@ -1054,8 +1058,8 @@ describe('unexpected-dom', function () { '
hey
' ); @@ -1075,6 +1079,7 @@ describe('unexpected-dom', function () { '\n' + '
\n' + ' foobar // should equal \'hey\'\n' + + ' //\n' + ' // -foobar\n' + ' // +hey\n' + '
' @@ -1125,8 +1130,8 @@ describe('unexpected-dom', function () { '
hey
' ); @@ -1208,6 +1213,7 @@ describe('unexpected-dom', function () { '\n' + '
\n' + ' hey // should equal \'there\'\n' + + ' //\n' + ' // -hey\n' + ' // +there\n' + '
' @@ -1736,6 +1742,7 @@ describe('unexpected-dom', function () { ' pr\n' + ' \n' + ' otected // should equal \'odtected\'\n' + + ' //\n' + ' // -otected\n' + ' // +odtected\n' + ' \n' + From 5bed07aaa73a94beb8cd1b6c3b8b64a7dd498be1 Mon Sep 17 00:00:00 2001 From: Andreas Lind Date: Wed, 23 Dec 2015 13:26:15 +0100 Subject: [PATCH 2/5] Use compound assertions. --- test/unexpected-dom.js | 22 +++++++++++----------- 1 file changed, 11 insertions(+), 11 deletions(-) diff --git a/test/unexpected-dom.js b/test/unexpected-dom.js index acbc9523..fa5dfb5a 100644 --- a/test/unexpected-dom.js +++ b/test/unexpected-dom.js @@ -820,7 +820,7 @@ describe('unexpected-dom', function () { describe('with an HTML fragment string passed as the children attribute', function () { it('should succeed', function () { - expect('
foobar
', 'when parsed as HTML fragment', 'to satisfy', [ + expect('
foobar
', 'when parsed as HTML fragment to satisfy', [ { name: 'div', children: 'foobar' @@ -830,7 +830,7 @@ describe('unexpected-dom', function () { it('should fail with a diff', function () { expect(function () { - expect('
foobar
', 'when parsed as HTML fragment', 'to satisfy', [ + expect('
foobar
', 'when parsed as HTML fragment to satisfy', [ { name: 'div', children: 'barfoo' @@ -855,12 +855,12 @@ describe('unexpected-dom', function () { describe('HTMLFragment', function () { describe('with a string as the value', function () { it('should succeed', function () { - expect('
foo
bar
', 'when parsed as HTML fragment', 'to satisfy', '
foo
bar
'); + expect('
foo
bar
', 'when parsed as HTML fragment to satisfy', '
foo
bar
'); }); it('should fail with an error', function () { expect(function () { - expect('
foo
bar
', 'when parsed as HTML fragment', 'to satisfy', '
quux
bar
'); + expect('
foo
bar
', 'when parsed as HTML fragment to satisfy', '
quux
bar
'); }, 'to throw', 'expected \'
foo
bar
\'\n' + 'when parsed as HTML fragment to satisfy \'
quux
bar
\'\n' + @@ -885,7 +885,7 @@ describe('unexpected-dom', function () { describe('with the exhaustively flag', function () { it('should fail with a diff', function () { expect(function () { - expect('
foo
bar
', 'when parsed as HTML fragment', 'to exhaustively satisfy', '
foo
bar
'); + expect('
foo
bar
', 'when parsed as HTML fragment to exhaustively satisfy', '
foo
bar
'); }, 'to throw', 'expected \'
foo
bar
\'\n' + 'when parsed as HTML fragment to exhaustively satisfy \'
foo
bar
\'\n' + @@ -903,12 +903,12 @@ describe('unexpected-dom', function () { describe('with an HTMLFragment as the value', function () { it('should succeed', function () { - expect('
foo
bar
', 'when parsed as HTML fragment', 'to satisfy', parseHtmlFragment('
foo
bar
')); + expect('
foo
bar
', 'when parsed as HTML fragment to satisfy', parseHtmlFragment('
foo
bar
')); }); it('should fail with an error', function () { expect(function () { - expect('
foo
bar
', 'when parsed as HTML fragment', 'to satisfy', parseHtmlFragment('
quux
bar
')); + expect('
foo
bar
', 'when parsed as HTML fragment to satisfy', parseHtmlFragment('
quux
bar
')); }, 'to throw', 'expected \'
foo
bar
\'\n' + 'when parsed as HTML fragment to satisfy DocumentFragment[NodeList[
quux
,
bar
]]\n' + @@ -932,7 +932,7 @@ describe('unexpected-dom', function () { describe('with an array as the value', function () { it('should succeed', function () { - expect('
foo
bar
', 'when parsed as HTML fragment', 'to satisfy', [ + expect('
foo
bar
', 'when parsed as HTML fragment to satisfy', [ { attributes: { foo: 'bar' }, children: [ 'foo' ] }, { name: 'div', children: [ 'bar' ] } ]); @@ -940,7 +940,7 @@ describe('unexpected-dom', function () { it('should fail with an error', function () { expect(function () { - expect('
foo
foobar
', 'when parsed as HTML fragment', 'to satisfy', [ + expect('
foo
foobar
', 'when parsed as HTML fragment to satisfy', [ { attributes: { foo: 'bar' }, children: [ 'foo' ] }, { name: 'div', children: [ 'bar' ] } ]); @@ -975,14 +975,14 @@ describe('unexpected-dom', function () { describe('with an object as the value', function () { it('should succeed', function () { - expect('
foo
bar
', 'when parsed as HTML fragment', 'to satisfy', { + expect('
foo
bar
', 'when parsed as HTML fragment to satisfy', { 1: { name: 'div', children: [ 'bar' ] } }); }); it('should fail with an error', function () { expect(function () { - expect('
foo
foobar
', 'when parsed as HTML fragment', 'to satisfy', { + expect('
foo
foobar
', 'when parsed as HTML fragment to satisfy', { 1: { name: 'div', children: [ 'bar' ] } }); }, 'to throw', From 498bd1bfb065d111e9951dd383f40459f4cbc568 Mon Sep 17 00:00:00 2001 From: Andreas Lind Date: Wed, 23 Dec 2015 13:35:16 +0100 Subject: [PATCH 3/5] Update sinon to 1.17.2. --- package.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/package.json b/package.json index f9b950de..cf672039 100644 --- a/package.json +++ b/package.json @@ -42,7 +42,7 @@ "magicpen": "^4.3.5", "mocha": "^2.1.0", "mocha-lcov-reporter": "1.0.0", - "sinon": "^1.15.4", + "sinon": "1.17.2", "uglifyjs": "^2.4.10", "unexpected": "10.5.0", "unexpected-sinon": "8.0.0" From d3c0d0271b9b22ab414a3e5c6967b5ea3dad7d10 Mon Sep 17 00:00:00 2001 From: Andreas Lind Date: Wed, 23 Dec 2015 13:35:23 +0100 Subject: [PATCH 4/5] Update unexpected-sinon to 9.0.4. --- package.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/package.json b/package.json index cf672039..ae700eac 100644 --- a/package.json +++ b/package.json @@ -45,7 +45,7 @@ "sinon": "1.17.2", "uglifyjs": "^2.4.10", "unexpected": "10.5.0", - "unexpected-sinon": "8.0.0" + "unexpected-sinon": "9.0.4" }, "dependencies": { "array-changes": "1.0.3", From 076d1f44c1c7df3e515d6a47853bc2065dba5586 Mon Sep 17 00:00:00 2001 From: Andreas Lind Date: Wed, 23 Dec 2015 13:35:37 +0100 Subject: [PATCH 5/5] Use the 'to have calls satisfying' assertion in the tests. --- test/unexpected-dom.js | 49 +++++++++++++++++++----------------------- 1 file changed, 22 insertions(+), 27 deletions(-) diff --git a/test/unexpected-dom.js b/test/unexpected-dom.js index fa5dfb5a..321655a8 100644 --- a/test/unexpected-dom.js +++ b/test/unexpected-dom.js @@ -1569,9 +1569,9 @@ describe('unexpected-dom', function () { return { parseFromString: parseFromStringSpy = sinon.spy(function (htmlString, contentType) { return jsdom.jsdom(htmlString); - }) + }).named('parseFromString') }; - }); + }).named('DOMParser'); }); afterEach(function () { global.DOMParser = originalDOMParser; @@ -1579,11 +1579,10 @@ describe('unexpected-dom', function () { it('should use DOMParser to parse the document', function () { expect(htmlSrc, 'when parsed as HTML', 'queried for first', 'body', 'to have text', 'foo'); - expect(DOMParserSpy, 'was called once'); - expect(DOMParserSpy, 'was called with'); - expect(DOMParserSpy.calledWithNew(), 'to be true'); - expect(parseFromStringSpy, 'was called once'); - expect(parseFromStringSpy, 'was called with', htmlSrc, 'text/html'); + expect([DOMParserSpy, parseFromStringSpy], 'to have calls satisfying', function () { + new DOMParserSpy(); + parseFromStringSpy(htmlSrc, 'text/html'); + }); }); }); @@ -1598,11 +1597,11 @@ describe('unexpected-dom', function () { implementation: { createHTMLDocument: createHTMLDocumentSpy = sinon.spy(function () { mockDocument = jsdom.jsdom(htmlSrc); - mockDocument.open = sinon.spy(); - mockDocument.write = sinon.spy(); - mockDocument.close = sinon.spy(); + mockDocument.open = sinon.spy().named('document.open'); + mockDocument.write = sinon.spy().named('document.write'); + mockDocument.close = sinon.spy().named('document.close'); return mockDocument; - }) + }).named('createHTMLDocument') } }; }); @@ -1612,15 +1611,12 @@ describe('unexpected-dom', function () { it('should use document.implementation.createHTMLDocument to parse the document', function () { expect(htmlSrc, 'when parsed as HTML', 'queried for first', 'body', 'to have text', 'foo'); - expect(createHTMLDocumentSpy, 'was called once'); - expect(createHTMLDocumentSpy, 'was called with'); - expect(mockDocument.open, 'was called once'); - expect(mockDocument.write, 'was called with'); - expect(mockDocument.write, 'was called once'); - expect(mockDocument.write, 'was called with', htmlSrc); - expect(mockDocument.close, 'was called once'); - expect(mockDocument.write, 'was called with'); - expect([mockDocument.open, mockDocument.write, mockDocument.close], 'given call order'); + expect([createHTMLDocumentSpy, mockDocument.open, mockDocument.write, mockDocument.close], 'to have calls satisfying', function () { + createHTMLDocumentSpy(''); + mockDocument.open(); + mockDocument.write(htmlSrc); + mockDocument.close(); + }); }); }); }); @@ -1652,9 +1648,9 @@ describe('unexpected-dom', function () { return { parseFromString: parseFromStringSpy = sinon.spy(function (xmlString, contentType) { return jsdom.jsdom(xmlString, { parsingMode: 'xml' }); - }) + }).named('parseFromString') }; - }); + }).named('DOMParser'); }); afterEach(function () { global.DOMParser = originalDOMParser; @@ -1662,11 +1658,10 @@ describe('unexpected-dom', function () { it('should use DOMParser to parse the document', function () { expect(xmlSrc, 'when parsed as XML', 'queried for first', 'fooBar', 'to have text', 'foo'); - expect(DOMParserSpy, 'was called once'); - expect(DOMParserSpy, 'was called with'); - expect(DOMParserSpy.calledWithNew(), 'to be true'); - expect(parseFromStringSpy, 'was called once'); - expect(parseFromStringSpy, 'was called with', xmlSrc, 'text/xml'); + expect([DOMParserSpy, parseFromStringSpy], 'to have calls satisfying', function () { + new DOMParserSpy(); + parseFromStringSpy(xmlSrc, 'text/xml'); + }); }); }); });