diff --git a/test/index.spec.js b/test/index.spec.js index 5a06ceb2..ff232af9 100644 --- a/test/index.spec.js +++ b/test/index.spec.js @@ -8,6 +8,16 @@ it.skipIf = function(bool, descr, block) { (bool ? it.skip : it)(descr, block); }; +expect.addAssertion( + ' to error satisfying ', + (expect, cb) => + expect(cb, 'to error').then(err => + expect.shift( + err.isUnexpected ? err.getErrorMessage('text').toString() : err.message + ) + ) +); + expect.addAssertion( ' to throw an error satisfying ', (expect, cb) => @@ -1853,13 +1863,14 @@ describe('unexpected-dom', () => { 'to satisfy', '
hey
' ), - 'to error', - 'expected
hey
to satisfy
hey
\n' + - '\n' + - 'hey' + 'to error satisfying to equal snapshot', expect.unindent` + expected
hey
to satisfy
hey
+ +
hey
+ ` )); it('should succeed when the subject has an extra class', () => @@ -1877,12 +1888,13 @@ describe('unexpected-dom', () => { 'to satisfy', '
hey
' ), - 'to error', - 'expected
hey
to satisfy
hey
\n' + - '\n' + - 'hey' + 'to error satisfying to equal snapshot', expect.unindent` + expected
hey
to satisfy
hey
+ +
hey
+ ` )); it('should succeed when the subject has an extra inline style', () => @@ -1900,17 +1912,18 @@ describe('unexpected-dom', () => { 'to satisfy', '
hey
' ), - 'to error', - 'expected
hey
to satisfy
hey
\n' + - '\n' + - 'hey' + 'to error satisfying to equal snapshot', expect.unindent` + expected
hey
to satisfy
hey
+ +
hey
+ ` )); }); @@ -1930,15 +1943,16 @@ describe('unexpected-dom', () => { 'to satisfy', parseHtml('
hey
') ), - 'to error', - 'expected
foobar
to satisfy
hey
\n' + - '\n' + - '
\n' + - " foobar // should equal 'hey'\n" + - ' //\n' + - ' // -foobar\n' + - ' // +hey\n' + - '
' + 'to error satisfying to equal snapshot', expect.unindent` + expected
foobar
to satisfy
hey
+ +
+ foobar // should equal 'hey' + // + // -foobar + // +hey +
+ ` )); it('should succeed when the subject equals the value parsed as HTML', () => @@ -1956,13 +1970,14 @@ describe('unexpected-dom', () => { 'to satisfy', parseHtml('
hey
') ), - 'to error', - 'expected
hey
to satisfy
hey
\n' + - '\n' + - 'hey' + 'to error satisfying to equal snapshot', expect.unindent` + expected
hey
to satisfy
hey
+ +
hey
+ ` )); it('should succeed when the subject has an extra class', () => @@ -1980,12 +1995,13 @@ describe('unexpected-dom', () => { 'to satisfy', parseHtml('
hey
') ), - 'to error', - 'expected
hey
to satisfy
hey
\n' + - '\n' + - 'hey' + 'to error satisfying to equal snapshot', expect.unindent` + expected
hey
to satisfy
hey
+ +
hey
+ ` )); it('should succeed when the subject has an extra inline style', () => @@ -2037,15 +2053,16 @@ describe('unexpected-dom', () => { 'to satisfy', parseHtml('
hey
') ), - 'to error', - 'expected
hey
\n' + - 'to satisfy
hey
\n' + - '\n' + - 'hey\n' + - " // to satisfy { name: 'div', attributes: { style: 'border-left-color: #FFFF;' }, children: [ 'hey' ] }\n" + - " // Expectation contains invalid styles: 'border-left-color: #FFFF'\n" + - '>hey' + 'to error satisfying to equal snapshot', expect.unindent` + expected
hey
+ to satisfy
hey
+ +
hey
+ // to satisfy { name: 'div', attributes: { style: 'border-left-color: #FFFF;' }, children: [ 'hey' ] } + // Expectation contains invalid styles: 'border-left-color: #FFFF' + >hey + ` ) ); @@ -2057,14 +2074,15 @@ describe('unexpected-dom', () => { 'to satisfy', parseHtml('
hey
') ), - 'to error', - 'expected
hey
to satisfy
hey
\n' + - '\n' + - 'hey\n' + - " // to satisfy { name: 'div', attributes: { style: 'color;background;width: 120px' }, children: [ 'hey' ] }\n" + - " // Expectation contains invalid styles: 'color;background'\n" + - '>hey' + 'to error satisfying to equal snapshot', expect.unindent` + expected
hey
to satisfy
hey
+ +
hey
+ // to satisfy { name: 'div', attributes: { style: 'color;background;width: 120px' }, children: [ 'hey' ] } + // Expectation contains invalid styles: 'color;background' + >hey + ` ) ); @@ -2076,17 +2094,18 @@ describe('unexpected-dom', () => { 'to satisfy', parseHtml('
hey
') ), - 'to error', - 'expected
hey
to satisfy
hey
\n' + - '\n' + - 'hey' + 'to error satisfying to equal snapshot', expect.unindent` + expected
hey
to satisfy
hey
+ +
hey
+ ` )); }); @@ -2105,13 +2124,14 @@ describe('unexpected-dom', () => { }); it('should fail with a diff', () => { - expect( - () => { - expect(parseHtml('foobar'), 'to satisfy', parseHtml('bar')); - }, - 'to error', - 'expected foobar to satisfy bar\n' + '\n' + '-foobar\n' + '+bar' - ); + expect(() => { + expect(parseHtml('foobar'), 'to satisfy', parseHtml('bar')); + }, 'to error satisfying to equal snapshot', expect.unindent` + expected foobar to satisfy bar + + -foobar + +bar + `); }); }); @@ -2126,13 +2146,9 @@ describe('unexpected-dom', () => { }); it('should fail with a diff', () => { - expect( - () => { - expect(parseHtml('foobar'), 'to satisfy', /^f00/); - }, - 'to error', - 'expected foobar to satisfy /^f00/' - ); + expect(() => { + expect(parseHtml('foobar'), 'to satisfy', /^f00/); + }, 'to error satisfying to equal snapshot', 'expected foobar to satisfy /^f00/'); }); }); @@ -2555,12 +2571,14 @@ describe('unexpected-dom', () => { '
', 'diffed with', '
', - 'to equal', - '
\n' + - '
\n' + - '
\n' + - '
' + 'to equal snapshot', + expect.unindent` +
+
+
+
+ ` ); }); @@ -2569,13 +2587,15 @@ describe('unexpected-dom', () => { '
foo
', 'diffed with', '
quux
', - 'to equal', - '
\n' + - ' -foo\n' + - ' +quux\n' + - ' -\n' + - ' +\n' + - '
' + 'to equal snapshot', + expect.unindent` +
+ -foo + +quux + - + + +
+ ` ); }); @@ -2584,12 +2604,14 @@ describe('unexpected-dom', () => { '
foo
', 'diffed with', '
foo
', - 'to equal', - '
\n' + - ' foo\n' + - ' // missing \n' + - ' \n' + - '
' + 'to equal snapshot', + expect.unindent` +
+ foo + // missing + +
+ ` ); }); @@ -2598,12 +2620,14 @@ describe('unexpected-dom', () => { '
foo
', 'diffed with', '
foo
', - 'to equal', - '
\n' + - ' foo\n' + - ' // should be removed\n' + - ' \n' + - '
' + 'to equal snapshot', + expect.unindent` +
+ foo + // should be removed + +
+ ` ); }); @@ -2612,17 +2636,19 @@ describe('unexpected-dom', () => { '
foofoo
', 'diffed with', '
foobar
', - 'to equal', - '
\n' + - ' foo\n' + - ' \n' + - ' \n' + - ' -foo\n' + - ' +bar\n' + - ' \n' + - ' \n' + - ' \n' + - '
' + 'to equal snapshot', + expect.unindent` +
+ foo + + + -foo + +bar + + + +
+ ` ); }); @@ -2631,19 +2657,21 @@ describe('unexpected-dom', () => { '
foofoo
', 'diffed with', '
foobar
', - 'to equal', - '
\n' + - ' foo\n' + - ' \n' + - ' \n' + - ' -foo\n' + - ' +bar\n' + - ' \n' + - ' \n' + - ' \n' + - '
' + 'to equal snapshot', + expect.unindent` +
+ foo + + + -foo + +bar + + + +
+ ` ); }); @@ -2656,11 +2684,13 @@ describe('unexpected-dom', () => { parseHtmlDocument( '' ), - 'to equal', - '\n' + - ' // should be removed\n' + - '\n' + - ' // should be removed' + 'to equal snapshot', + expect.unindent` + + // should be removed + + // should be removed + ` ); }); }); @@ -3567,11 +3597,13 @@ describe('unexpected-dom', () => { ); }, 'to throw an error satisfying to equal snapshot', - 'expected
to contain \n' + - '\n' + - '\n' + - ' // missing \n' + - '' + expect.unindent` + expected
to contain + + + // missing + + ` ); }); @@ -3587,14 +3619,16 @@ describe('unexpected-dom', () => { ); }, 'to throw an error satisfying to equal snapshot', - 'expected
......
\n' + - 'to contain Hello!\n' + - '\n' + - '\n' + - ' Hello\n' + - ' world\n' + - " // missing '!'\n" + - '' + expect.unindent` + expected
......
+ to contain Hello! + + + Hello + world + // missing '!' + + ` ); }); @@ -3610,14 +3644,16 @@ describe('unexpected-dom', () => { ); }, 'to throw an error satisfying to equal snapshot', - 'expected
......!
\n' + - 'to contain Helloworld\n' + - '\n' + - '\n' + - ' Hello\n' + - ' world\n' + - ' ! // should be removed\n' + - '' + expect.unindent` + expected
......!
+ to contain Helloworld + + + Hello + world + ! // should be removed + + ` ); }); }); @@ -3664,24 +3700,24 @@ describe('unexpected-dom', () => { }, 'to throw an error satisfying to equal snapshot', expect.unindent` - expected -
- Hello - + expected +
+ Hello + + + Jane Doe + + and + John Doe +
+ not to contain Jane Doe + + Found: + Jane Doe - and - John Doe -
- not to contain Jane Doe - - Found: - - - Jane Doe - - ` + ` ); }); });