Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Also support the new options in the array-like diff, added tests.
- Loading branch information
1 parent
31de255
commit 8e1e096
Showing
2 changed files
with
133 additions
and
4 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,113 @@ | ||
/*global expect*/ | ||
describe('array-like type', function () { | ||
describe('with a subtype that disables indentation', function () { | ||
var clonedExpect = expect.clone(); | ||
|
||
clonedExpect.addType({ | ||
base: 'array-like', | ||
name: 'bogusarray', | ||
identify: Array.isArray, | ||
indent: false | ||
}); | ||
|
||
it('should not render the indentation when an instance is inspected in a multi-line context', function () { | ||
expect( | ||
clonedExpect.inspect([ | ||
'aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa', | ||
'bbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbb' | ||
]).toString(), | ||
'to equal', | ||
"[\n" + | ||
"'aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa',\n" + | ||
"'bbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbb'\n" + | ||
"]" | ||
); | ||
}); | ||
|
||
it('should not render the indentation when an instance is diffed', function () { | ||
expect( | ||
clonedExpect.diff(['a', 'b'], ['aa', 'bb']).diff.toString(), | ||
'to equal', | ||
"[\n" + | ||
"'a', // should equal 'aa'\n" + | ||
" // -a\n" + | ||
" // +aa\n" + | ||
"'b' // should equal 'bb'\n" + | ||
" // -b\n" + | ||
" // +bb\n" + | ||
"]" | ||
); | ||
}); | ||
|
||
it('should not render the indentation when an instance participates in a "to satisfy" diff', function () { | ||
expect(function () { | ||
clonedExpect(['aaa', 'bbb'], 'to satisfy', { 0: 'foo' }); | ||
}, 'to throw', | ||
"expected [ 'aaa', 'bbb' ] to satisfy { 0: 'foo' }\n" + | ||
"\n" + | ||
"[\n" + | ||
"'aaa', // should equal 'foo'\n" + | ||
" // -aaa\n" + | ||
" // +foo\n" + | ||
"'bbb'\n" + | ||
"]" | ||
); | ||
}); | ||
}); | ||
|
||
describe('with a subtype that disables prefix, suffix, leading and trailing newline', function () { | ||
var clonedExpect = expect.clone(); | ||
|
||
clonedExpect.addType({ | ||
base: 'array-like', | ||
name: 'bogusarray', | ||
identify: Array.isArray, | ||
prefix: function (output) { | ||
return output; | ||
}, | ||
suffix: function (output) { | ||
return output; | ||
}, | ||
leadingNewline: false, | ||
trailingNewline: false | ||
}); | ||
|
||
it('should not render the newlines when an instance is inspected in a multi-line context', function () { | ||
expect( | ||
clonedExpect.inspect([ | ||
'aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa', | ||
'bbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbb' | ||
]).toString(), | ||
'to equal', | ||
" 'aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa',\n" + | ||
" 'bbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbb'" | ||
); | ||
}); | ||
|
||
it('should not render the newlines when an instance is diffed', function () { | ||
expect( | ||
clonedExpect.diff(['a', 'b'], ['aa', 'bb']).diff.toString(), | ||
'to equal', | ||
" 'a', // should equal 'aa'\n" + | ||
" // -a\n" + | ||
" // +aa\n" + | ||
" 'b' // should equal 'bb'\n" + | ||
" // -b\n" + | ||
" // +bb" | ||
); | ||
}); | ||
|
||
it('should not render the indentation when an instance participates in a "to satisfy" diff', function () { | ||
expect(function () { | ||
clonedExpect(['aaa', 'bbb'], 'to satisfy', { 0: 'foo' }); | ||
}, 'to throw', | ||
"expected 'aaa', 'bbb' to satisfy { 0: 'foo' }\n" + | ||
"\n" + | ||
" 'aaa', // should equal 'foo'\n" + | ||
" // -aaa\n" + | ||
" // +foo\n" + | ||
" 'bbb'" | ||
); | ||
}); | ||
}); | ||
}); |