Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

assert.throws needs better error messages #25

Open
zzggbb opened this issue Jul 24, 2017 · 0 comments
Open

assert.throws needs better error messages #25

zzggbb opened this issue Jul 24, 2017 · 0 comments

Comments

@zzggbb
Copy link

zzggbb commented Jul 24, 2017

  • If a function f throws ErrorB, assert.throws(f, ErrorA) and assert.notThrows(f, ErrorA) should signify the actual (ErrorB) and expected (ErrorA) errors rather than just throwing ErrorB

  • ErrorB is also swallowed as an AssertionError, rather than its true error type. For example, if there is a TypeError inside f, the TypeError message will be thrown as an AssertionError.

const f = function() { const x = 5; x = 6; }

// what currently happens
// AssertionError: Assignment to constant variable
assert.throws(f, ErrorA);
// AssertionError: Got unwanted exception
assert.notThrows(f, ErrorA);

// what should happen
// AssertionError: you caught the wrong exception (actual: TypeError, expected: ErrorA)
assert.throws(f, ErrorA);
// AssertionError: f threw an unwanted exception (actual: TypeError, expected: ErrorA)
assert.notThrows(f, ErrorA);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Development

No branches or pull requests

1 participant