Skip to content

Commit 5d2afb2

Browse files
gwerMylesBorins
authored andcommittedApr 16, 2018
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: #19447 PR-URL: #12604 Refs: #12586 Reviewed-By: Alexey Orlenko <eaglexrlnk@gmail.com> Reviewed-By: James M Snell <jasnell@gmail.com> Reviewed-By: Gibson Fahnestock <gibfahn@gmail.com>
1 parent 3e388cf commit 5d2afb2

File tree

2 files changed

+16
-16
lines changed

2 files changed

+16
-16
lines changed
 

‎test/addons-napi/test_constructor/test.js

+8-8
Original file line numberDiff line numberDiff line change
@@ -22,14 +22,14 @@ const propertyNames = [];
2222
for (const name in test_object) {
2323
propertyNames.push(name);
2424
}
25-
assert.ok(propertyNames.indexOf('echo') >= 0);
26-
assert.ok(propertyNames.indexOf('readwriteValue') >= 0);
27-
assert.ok(propertyNames.indexOf('readonlyValue') >= 0);
28-
assert.ok(propertyNames.indexOf('hiddenValue') < 0);
29-
assert.ok(propertyNames.indexOf('readwriteAccessor1') < 0);
30-
assert.ok(propertyNames.indexOf('readwriteAccessor2') < 0);
31-
assert.ok(propertyNames.indexOf('readonlyAccessor1') < 0);
32-
assert.ok(propertyNames.indexOf('readonlyAccessor2') < 0);
25+
assert.ok(propertyNames.includes('echo'));
26+
assert.ok(propertyNames.includes('readwriteValue'));
27+
assert.ok(propertyNames.includes('readonlyValue'));
28+
assert.ok(!propertyNames.includes('hiddenValue'));
29+
assert.ok(!propertyNames.includes('readwriteAccessor1'));
30+
assert.ok(!propertyNames.includes('readwriteAccessor2'));
31+
assert.ok(!propertyNames.includes('readonlyAccessor1'));
32+
assert.ok(!propertyNames.includes('readonlyAccessor2'));
3333

3434
// The napi_writable attribute should be ignored for accessors.
3535
test_object.readwriteAccessor1 = 1;

‎test/addons-napi/test_properties/test.js

+8-8
Original file line numberDiff line numberDiff line change
@@ -21,14 +21,14 @@ const propertyNames = [];
2121
for (const name in test_object) {
2222
propertyNames.push(name);
2323
}
24-
assert.ok(propertyNames.indexOf('echo') >= 0);
25-
assert.ok(propertyNames.indexOf('readwriteValue') >= 0);
26-
assert.ok(propertyNames.indexOf('readonlyValue') >= 0);
27-
assert.ok(propertyNames.indexOf('hiddenValue') < 0);
28-
assert.ok(propertyNames.indexOf('readwriteAccessor1') < 0);
29-
assert.ok(propertyNames.indexOf('readwriteAccessor2') < 0);
30-
assert.ok(propertyNames.indexOf('readonlyAccessor1') < 0);
31-
assert.ok(propertyNames.indexOf('readonlyAccessor2') < 0);
24+
assert.ok(propertyNames.includes('echo'));
25+
assert.ok(propertyNames.includes('readwriteValue'));
26+
assert.ok(propertyNames.includes('readonlyValue'));
27+
assert.ok(!propertyNames.includes('hiddenValue'));
28+
assert.ok(!propertyNames.includes('readwriteAccessor1'));
29+
assert.ok(!propertyNames.includes('readwriteAccessor2'));
30+
assert.ok(!propertyNames.includes('readonlyAccessor1'));
31+
assert.ok(!propertyNames.includes('readonlyAccessor2'));
3232

3333
// The napi_writable attribute should be ignored for accessors.
3434
test_object.readwriteAccessor1 = 1;

0 commit comments

Comments
 (0)
Please sign in to comment.