mirror of
https://github.com/nodejs/node.git
synced 2026-11-25 23:01:06 -05:00
test: replace indexOf with includes
Start the transition to Array.prototype.includes() and String.prototype.includes(). This commit refactors most of the comparisons of Array.prototype.indexOf() and String.prototype.indexOf() return values with -1 to the former methods in tests. Backport-PR-URL: https://github.com/nodejs/node/pull/19447 PR-URL: https://github.com/nodejs/node/pull/12604 Refs: https://github.com/nodejs/node/issues/12586 Reviewed-By: Alexey Orlenko <eaglexrlnk@gmail.com> Reviewed-By: James M Snell <jasnell@gmail.com> Reviewed-By: Gibson Fahnestock <gibfahn@gmail.com>
This commit is contained in:
1 parent
3e388cf819
commit
5d2afb2174
2 files changed
+16
-16
No files matched your search
@@ -22,14 +22,14 @@ const propertyNames = [];
|
||||
for (const name in test_object) {
|
||||
propertyNames.push(name);
|
||||
}
|
||||
assert.ok(propertyNames.indexOf('echo') >= 0);
|
||||
assert.ok(propertyNames.indexOf('readwriteValue') >= 0);
|
||||
assert.ok(propertyNames.indexOf('readonlyValue') >= 0);
|
||||
assert.ok(propertyNames.indexOf('hiddenValue') < 0);
|
||||
assert.ok(propertyNames.indexOf('readwriteAccessor1') < 0);
|
||||
assert.ok(propertyNames.indexOf('readwriteAccessor2') < 0);
|
||||
assert.ok(propertyNames.indexOf('readonlyAccessor1') < 0);
|
||||
assert.ok(propertyNames.indexOf('readonlyAccessor2') < 0);
|
||||
assert.ok(propertyNames.includes('echo'));
|
||||
assert.ok(propertyNames.includes('readwriteValue'));
|
||||
assert.ok(propertyNames.includes('readonlyValue'));
|
||||
assert.ok(!propertyNames.includes('hiddenValue'));
|
||||
assert.ok(!propertyNames.includes('readwriteAccessor1'));
|
||||
assert.ok(!propertyNames.includes('readwriteAccessor2'));
|
||||
assert.ok(!propertyNames.includes('readonlyAccessor1'));
|
||||
assert.ok(!propertyNames.includes('readonlyAccessor2'));
|
||||
|
||||
// The napi_writable attribute should be ignored for accessors.
|
||||
test_object.readwriteAccessor1 = 1;
|
||||
|
||||
@@ -21,14 +21,14 @@ const propertyNames = [];
|
||||
for (const name in test_object) {
|
||||
propertyNames.push(name);
|
||||
}
|
||||
assert.ok(propertyNames.indexOf('echo') >= 0);
|
||||
assert.ok(propertyNames.indexOf('readwriteValue') >= 0);
|
||||
assert.ok(propertyNames.indexOf('readonlyValue') >= 0);
|
||||
assert.ok(propertyNames.indexOf('hiddenValue') < 0);
|
||||
assert.ok(propertyNames.indexOf('readwriteAccessor1') < 0);
|
||||
assert.ok(propertyNames.indexOf('readwriteAccessor2') < 0);
|
||||
assert.ok(propertyNames.indexOf('readonlyAccessor1') < 0);
|
||||
assert.ok(propertyNames.indexOf('readonlyAccessor2') < 0);
|
||||
assert.ok(propertyNames.includes('echo'));
|
||||
assert.ok(propertyNames.includes('readwriteValue'));
|
||||
assert.ok(propertyNames.includes('readonlyValue'));
|
||||
assert.ok(!propertyNames.includes('hiddenValue'));
|
||||
assert.ok(!propertyNames.includes('readwriteAccessor1'));
|
||||
assert.ok(!propertyNames.includes('readwriteAccessor2'));
|
||||
assert.ok(!propertyNames.includes('readonlyAccessor1'));
|
||||
assert.ok(!propertyNames.includes('readonlyAccessor2'));
|
||||
|
||||
// The napi_writable attribute should be ignored for accessors.
|
||||
test_object.readwriteAccessor1 = 1;
|
||||
|
||||
Reference in new issue
Block a user