Skip to content

Commit 4346e61

Browse files
lib: remove unnecessary bounded function following @aduh95 suggestions
1 parent 1025667 commit 4346e61

File tree

3 files changed

+13
-6
lines changed

3 files changed

+13
-6
lines changed

lib/assert.js

Lines changed: 11 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -179,8 +179,16 @@ assert.AssertionError = AssertionError;
179179
function ok(...args) {
180180
innerOk(ok, args.length, ...args);
181181
}
182-
Assert.prototype.ok = function(...args) {
183-
innerOk(this.ok, args.length, ...args);
182+
183+
/**
184+
* Pure assertion tests whether a value is truthy, as determined
185+
* by !!value.
186+
* Duplicated as the other `ok` function is supercharged and exposed as default export.
187+
* @param {...any} args
188+
* @returns {void}
189+
*/
190+
Assert.prototype.ok = function ok(...args) {
191+
innerOk(ok, args.length, ...args);
184192
};
185193

186194
/**
@@ -872,14 +880,13 @@ function strict(...args) {
872880
innerOk(strict, args.length, ...args);
873881
}
874882

875-
const assertInstance = new Assert({ diff: 'simple', strict: false });
876883
ArrayPrototypeForEach([
877884
'ok', 'fail', 'equal', 'notEqual', 'deepEqual', 'notDeepEqual',
878885
'deepStrictEqual', 'notDeepStrictEqual', 'strictEqual',
879886
'notStrictEqual', 'partialDeepStrictEqual', 'match', 'doesNotMatch',
880887
'throws', 'rejects', 'doesNotThrow', 'doesNotReject', 'ifError',
881888
], (name) => {
882-
setOwnProperty(assert, name, Assert.prototype[name].bind(assertInstance));
889+
setOwnProperty(assert, name, Assert.prototype[name]);
883890
});
884891

885892
assert.strict = ObjectAssign(strict, assert, {

test/message/assert_throws_stack.out

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ AssertionError [ERR_ASSERTION]: Expected values to be strictly deep-equal:
2424
actual: Error: foo
2525
at assert.throws.bar (*assert_throws_stack.js:*)
2626
at getActual (node:assert:*)
27-
at Assert.throws (node:assert:*)
27+
at strict.throws (node:assert:*)
2828
at Object.<anonymous> (*assert_throws_stack.js:*:*)
2929
at *
3030
at *

test/parallel/test-fs-promises.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -58,7 +58,7 @@ assert.strictEqual(
5858
code: 'ENOENT',
5959
name: 'Error',
6060
message: /^ENOENT: no such file or directory, access/,
61-
stack: /at async Assert\.rejects/
61+
stack: /at async ok\.rejects/
6262
}
6363
).then(common.mustCall());
6464

0 commit comments

Comments
 (0)