Skip to content

Commit

Permalink
Throw Error on failure (not simple string)
Browse files Browse the repository at this point in the history
  • Loading branch information
dubzzz committed Jan 30, 2018
1 parent 9f70e1f commit 6787cd4
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 6 deletions.
4 changes: 3 additions & 1 deletion src/check/runner/utils/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,9 @@ function pretty<Ts>(value: any): string {

function throwIfFailed<Ts>(out: RunDetails<Ts>) {
if (out.failed) {
throw `Property failed after ${out.num_runs} tests (seed: ${out.seed}): ${pretty(out.counterexample)}\nGot error: ${out.error}`;
throw new Error(
`Property failed after ${out.num_runs} tests (seed: ${out.seed}): ${pretty(out.counterexample)}\n` +
`Got error: ${out.error}`);
}
}

Expand Down
10 changes: 5 additions & 5 deletions test/unit/check/runner/Runner.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -158,7 +158,7 @@ describe('Runner', () => {
rAssert(failingProperty, {seed: 42});
}
catch (err) {
assert.ok(err.indexOf(`(seed: 42)`) !== -1, `Cannot find the seed in: ${err}`);
assert.ok(err.message.indexOf(`(seed: 42)`) !== -1, `Cannot find the seed in: ${err.message}`);
return;
}
assert.ok(false, "Expected an exception, got success");
Expand All @@ -168,7 +168,7 @@ describe('Runner', () => {
rAssert(failingProperty, {seed: 42});
}
catch (err) {
assert.ok(err.indexOf(`failed after 1 test`) !== -1, `Cannot find the number of tests in: ${err}`);
assert.ok(err.message.indexOf(`failed after 1 test`) !== -1, `Cannot find the number of tests in: ${err.message}`);
return;
}
assert.ok(false, "Expected an exception, got success");
Expand All @@ -178,7 +178,7 @@ describe('Runner', () => {
rAssert(failingProperty, {seed: 42});
}
catch (err) {
assert.ok(err.indexOf(`[${v1.toString()},${JSON.stringify(v2)}]`) !== -1, `Cannot find the example in: ${err}`);
assert.ok(err.message.indexOf(`[${v1.toString()},${JSON.stringify(v2)}]`) !== -1, `Cannot find the example in: ${err.message}`);
return;
}
assert.ok(false, "Expected an exception, got success");
Expand All @@ -188,7 +188,7 @@ describe('Runner', () => {
rAssert(failingComplexProperty, {seed: 42});
}
catch (err) {
assert.ok(err.indexOf(`[[${v1.toString()},${JSON.stringify(v2)}],${JSON.stringify(v2)},${v1.toString()}]`) !== -1, `Cannot find the example in: ${err}`);
assert.ok(err.message.indexOf(`[[${v1.toString()},${JSON.stringify(v2)}],${JSON.stringify(v2)},${v1.toString()}]`) !== -1, `Cannot find the example in: ${err.message}`);
return;
}
assert.ok(false, "Expected an exception, got success");
Expand All @@ -198,7 +198,7 @@ describe('Runner', () => {
rAssert(failingProperty, {seed: 42});
}
catch (err) {
assert.ok(err.indexOf(`Got error: error in failingProperty`) !== -1, `Cannot find the original error in: ${err}`);
assert.ok(err.message.indexOf(`Got error: error in failingProperty`) !== -1, `Cannot find the original error in: ${err.message}`);
return;
}
assert.ok(false, "Expected an exception, got success");
Expand Down

0 comments on commit 6787cd4

Please sign in to comment.