-
Notifications
You must be signed in to change notification settings - Fork 29.8k
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
tools: enforce two arguments in assert.throws #12270
Conversation
assert.throws(() => { test_object.readonlyValue = 3; }); | ||
const expected = new RegExp( | ||
'^TypeError: Cannot assign to read only property \'readonlyValue\' of ' + | ||
'object \'#<MyObject>\'$' |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Matching the complete error message seems fragile. What if V8 changes the wording of the error message?
Would matching the type of error object be sufficient, using the overload of assert.throws()
that takes a constructor?
assert.throws(() => { /* some code that throws a TypeError */ }, TypeError);
@@ -45,7 +45,8 @@ function re(literals, ...values) { | |||
} | |||
assert.doesNotThrow(() => assert.deepEqual(fakeGlobal, global)); | |||
// Message will be truncated anyway, don't validate | |||
assert.throws(() => assert.deepStrictEqual(fakeGlobal, global)); | |||
assert.throws(() => assert.deepStrictEqual(fakeGlobal, global), | |||
/^AssertionError: /); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
As above, consider just passing the AssertionError
constructor here instead of a regexp.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Will do. I actually tried to put AssertionError
first but realized it's not globally available. Your comment made me look closer and I saw that it is exported by the assert
module.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM (with changes suggested by @jasongin). I'm slightly bummed about this, though, because I was going to hand all these changes out at Code + Learn later this month. :-D
ae3e425
to
efdf030
Compare
This adds RegExp or error constructor arguments to the remaining places where it is missing in preparation for the commit that will enforce the presence of at least two arguments. PR-URL: nodejs#12270 Reviewed-By: Colin Ihrig <cjihrig@gmail.com> Reviewed-By: Rich Trott <rtrott@gmail.com>
Enables the requireTwo option of our custom rule. PR-URL: nodejs#12270 Reviewed-By: Colin Ihrig <cjihrig@gmail.com> Reviewed-By: Rich Trott <rtrott@gmail.com>
efdf030
to
a4b9c58
Compare
Should this be backported to |
@targos when you merge multiple commits, could you still comment with |
Backport PR: #13785 |
This adds RegExp or error constructor arguments to the remaining places where it is missing in preparation for the commit that will enforce the presence of at least two arguments. PR-URL: #12270 Backport-PR-URL: #13785 Reviewed-By: Colin Ihrig <cjihrig@gmail.com> Reviewed-By: Rich Trott <rtrott@gmail.com>
This adds RegExp or error constructor arguments to the remaining places where it is missing in preparation for the commit that will enforce the presence of at least two arguments. PR-URL: #12270 Backport-PR-URL: #13785 Reviewed-By: Colin Ihrig <cjihrig@gmail.com> Reviewed-By: Rich Trott <rtrott@gmail.com>
This adds RegExp or error constructor arguments to the remaining places where it is missing in preparation for the commit that will enforce the presence of at least two arguments. PR-URL: #12270 Backport-PR-URL: #13785 Reviewed-By: Colin Ihrig <cjihrig@gmail.com> Reviewed-By: Rich Trott <rtrott@gmail.com>
This adds RegExp or error constructor arguments to the remaining places where it is missing in preparation for the commit that will enforce the presence of at least two arguments. PR-URL: nodejs#12270 Reviewed-By: Colin Ihrig <cjihrig@gmail.com> Reviewed-By: Rich Trott <rtrott@gmail.com>
This adds RegExp or error constructor arguments to the remaining places where it is missing in preparation for the commit that will enforce the presence of at least two arguments. Backport-PR-URL: #19447 PR-URL: #12270 Reviewed-By: Colin Ihrig <cjihrig@gmail.com> Reviewed-By: Rich Trott <rtrott@gmail.com>
This adds RegExp or error constructor arguments to the remaining places where it is missing in preparation for the commit that will enforce the presence of at least two arguments. PR-URL: nodejs/node#12270 Reviewed-By: Colin Ihrig <cjihrig@gmail.com> Reviewed-By: Rich Trott <rtrott@gmail.com>
Enables the requireTwo option of our custom rule. PR-URL: nodejs/node#12270 Reviewed-By: Colin Ihrig <cjihrig@gmail.com> Reviewed-By: Rich Trott <rtrott@gmail.com>
First commit adds a RegExp argument to the remaining places where it is missing in preparation for the second commit that enforces the presence of at least two arguments in
assert.throws()
.Checklist
make -j4 test
(UNIX), orvcbuild test
(Windows) passesAffected core subsystem(s)
test, tools