Skip to content

Commit 7c73311

Browse files
committed
Only rely on input shrinking to find the best error
1 parent b5e309a commit 7c73311

File tree

2 files changed

+6
-30
lines changed

2 files changed

+6
-30
lines changed

lib/unexpected-check.js

+2-26
Original file line numberDiff line numberDiff line change
@@ -34,18 +34,6 @@
3434
return {
3535
name: 'unexpected-check',
3636
installInto: function (expect) {
37-
function convertToUnexpectedError(e) {
38-
if (e && e.isUnexpected) {
39-
return e;
40-
}
41-
42-
try {
43-
expect.fail({ message: e.message });
44-
} catch (unexpectedError) {
45-
return unexpectedError;
46-
}
47-
}
48-
4937
expect.addAssertion('<function> to be valid for all <object>', function (expect, subject, options) {
5038
var generators = options.generators;
5139
var maxIterations = options.maxIterations || 300;
@@ -66,7 +54,7 @@
6654
generators = generators.map(function (g, i) {
6755
return g.shrink ? g.shrink(args[i]) : g;
6856
});
69-
task.error = convertToUnexpectedError(e);
57+
task.error = e
7058
}
7159

7260
return task;
@@ -92,19 +80,7 @@
9280
});
9381

9482
if (failedTasks.length > 0) {
95-
var bestFailure = failedTasks[0];
96-
var currentSize;
97-
failedTasks.forEach(function (task) {
98-
currentSize = currentSize || bestFailure.error.getErrorMessage('text').size();
99-
var newSize = task.error.getErrorMessage('text').size();
100-
if (
101-
(newSize.height < currentSize.height) ||
102-
(newSize.height === currentSize.height && newSize.width < currentSize.width)
103-
) {
104-
bestFailure = task;
105-
currentSize = newSize;
106-
}
107-
});
83+
var bestFailure = failedTasks[failedTasks.length - 1];
10884

10985
expect.errorMode = 'bubble';
11086
expect.fail(function (output) {

test/unexpected-check.spec.js

+4-4
Original file line numberDiff line numberDiff line change
@@ -50,13 +50,13 @@ describe('unexpected-check', function () {
5050
'Ran 20 iterations and found 12 errors\n' +
5151
'counterexample:\n' +
5252
'\n' +
53-
' Generated input: [ -15, -20 ]\n' +
53+
' Generated input: [ -20, -15 ]\n' +
5454
'\n' +
55-
' expected [ -15, -20 ] first item to be less than or equal to all [ -15, -20 ]\n' +
55+
' expected [ -15, -20 ] first item to be less than or equal to all [ -20, -15 ]\n' +
5656
'\n' +
5757
' [\n' +
58-
' -15,\n' +
59-
' -20 // should be greater than or equal to -15\n' +
58+
' -20, // should be greater than or equal to -15\n' +
59+
' -15\n' +
6060
' ]');
6161
});
6262

0 commit comments

Comments
 (0)