From 3461bc13da995e90031c18b8e9d7237d7b5c0106 Mon Sep 17 00:00:00 2001 From: gwer Date: Sun, 23 Apr 2017 02:01:54 +0300 Subject: [PATCH] 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. PR-URL: https://github.com/nodejs/node/pull/12604 Refs: https://github.com/nodejs/node/issues/12586 Reviewed-By: Alexey Orlenko Reviewed-By: James M Snell Reviewed-By: Gibson Fahnestock --- test/addons-napi/test_constructor/test.js | 16 ++++++++-------- test/addons-napi/test_properties/test.js | 16 ++++++++-------- 2 files changed, 16 insertions(+), 16 deletions(-) diff --git a/test/addons-napi/test_constructor/test.js b/test/addons-napi/test_constructor/test.js index 92440bf49e74c1..26083db7a28a21 100644 --- a/test/addons-napi/test_constructor/test.js +++ b/test/addons-napi/test_constructor/test.js @@ -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; diff --git a/test/addons-napi/test_properties/test.js b/test/addons-napi/test_properties/test.js index 868c603879f1a2..a8127a27860eb3 100644 --- a/test/addons-napi/test_properties/test.js +++ b/test/addons-napi/test_properties/test.js @@ -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;