test: flip assertion arguments for make-callback/test.js
Assertion arguments should have the first value be the actual value, while the second value be the expected value. PR-URL: https://github.com/nodejs/node/pull/23470 Reviewed-By: Colin Ihrig <cjihrig@gmail.com> Reviewed-By: Gireesh Punathil <gpunathi@in.ibm.com> Reviewed-By: James M Snell <jasnell@gmail.com> Reviewed-By: Trivikram Kamat <trivikr.dev@gmail.com>
This commit is contained in:
parent
e48d9aa873
commit
7f74515cd1
@ -6,39 +6,39 @@ const vm = require('vm');
|
|||||||
const binding = require(`./build/${common.buildType}/binding`);
|
const binding = require(`./build/${common.buildType}/binding`);
|
||||||
const makeCallback = binding.makeCallback;
|
const makeCallback = binding.makeCallback;
|
||||||
|
|
||||||
assert.strictEqual(42, makeCallback(process, common.mustCall(function() {
|
assert.strictEqual(makeCallback(process, common.mustCall(function() {
|
||||||
assert.strictEqual(0, arguments.length);
|
assert.strictEqual(arguments.length, 0);
|
||||||
assert.strictEqual(this, process);
|
assert.strictEqual(process, this);
|
||||||
return 42;
|
return 42;
|
||||||
})));
|
})), 42);
|
||||||
|
|
||||||
assert.strictEqual(42, makeCallback(process, common.mustCall(function(x) {
|
assert.strictEqual(makeCallback(process, common.mustCall(function(x) {
|
||||||
assert.strictEqual(1, arguments.length);
|
assert.strictEqual(arguments.length, 1);
|
||||||
assert.strictEqual(this, process);
|
assert.strictEqual(process, this);
|
||||||
assert.strictEqual(x, 1337);
|
assert.strictEqual(x, 1337);
|
||||||
return 42;
|
return 42;
|
||||||
}), 1337));
|
}), 1337), 42);
|
||||||
|
|
||||||
const recv = {
|
const recv = {
|
||||||
one: common.mustCall(function() {
|
one: common.mustCall(function() {
|
||||||
assert.strictEqual(0, arguments.length);
|
assert.strictEqual(arguments.length, 0);
|
||||||
assert.strictEqual(this, recv);
|
assert.strictEqual(recv, this);
|
||||||
return 42;
|
return 42;
|
||||||
}),
|
}),
|
||||||
two: common.mustCall(function(x) {
|
two: common.mustCall(function(x) {
|
||||||
assert.strictEqual(1, arguments.length);
|
assert.strictEqual(arguments.length, 1);
|
||||||
assert.strictEqual(this, recv);
|
assert.strictEqual(recv, this);
|
||||||
assert.strictEqual(x, 1337);
|
assert.strictEqual(x, 1337);
|
||||||
return 42;
|
return 42;
|
||||||
}),
|
}),
|
||||||
};
|
};
|
||||||
|
|
||||||
assert.strictEqual(42, makeCallback(recv, 'one'));
|
assert.strictEqual(makeCallback(recv, 'one'), 42);
|
||||||
assert.strictEqual(42, makeCallback(recv, 'two', 1337));
|
assert.strictEqual(makeCallback(recv, 'two', 1337), 42);
|
||||||
|
|
||||||
// Check that callbacks on a receiver from a different context works.
|
// Check that callbacks on a receiver from a different context works.
|
||||||
const foreignObject = vm.runInNewContext('({ fortytwo() { return 42; } })');
|
const foreignObject = vm.runInNewContext('({ fortytwo() { return 42; } })');
|
||||||
assert.strictEqual(42, makeCallback(foreignObject, 'fortytwo'));
|
assert.strictEqual(makeCallback(foreignObject, 'fortytwo'), 42);
|
||||||
|
|
||||||
// Check that the callback is made in the context of the receiver.
|
// Check that the callback is made in the context of the receiver.
|
||||||
const target = vm.runInNewContext(`
|
const target = vm.runInNewContext(`
|
||||||
@ -48,7 +48,7 @@ const target = vm.runInNewContext(`
|
|||||||
return Object;
|
return Object;
|
||||||
})
|
})
|
||||||
`);
|
`);
|
||||||
assert.notStrictEqual(Object, makeCallback(process, target, Object));
|
assert.notStrictEqual(makeCallback(process, target, Object), Object);
|
||||||
|
|
||||||
// Runs in inner context.
|
// Runs in inner context.
|
||||||
const forward = vm.runInNewContext(`
|
const forward = vm.runInNewContext(`
|
||||||
@ -62,4 +62,4 @@ function endpoint($Object) {
|
|||||||
throw new Error('bad');
|
throw new Error('bad');
|
||||||
return Object;
|
return Object;
|
||||||
}
|
}
|
||||||
assert.strictEqual(Object, makeCallback(process, forward, endpoint));
|
assert.strictEqual(makeCallback(process, forward, endpoint), Object);
|
||||||
|
Loading…
x
Reference in New Issue
Block a user