From 9d36afc65a8c0df25f82580767b740077a08793a Mon Sep 17 00:00:00 2001 From: Bryan Housel Date: Thu, 21 Dec 2023 17:39:28 -0500 Subject: [PATCH] Use instanceof checks for complex types, typeof for builtin types Also remove unneeded null check when `result instanceof Object` https://stackoverflow.com/questions/899574/what-is-the-difference-between-typeof-and-instanceof-and-when-should-one-be-used --- test/resolveLocation.test.js | 36 +++++++-------- test/resolveLocationSet.test.js | 77 ++++++++++++++------------------ test/validateLocation.test.js | 10 ++--- test/validateLocationSet.test.js | 51 +++++++-------------- 4 files changed, 73 insertions(+), 101 deletions(-) diff --git a/test/resolveLocation.test.js b/test/resolveLocation.test.js index 1464b41..bc666af 100644 --- a/test/resolveLocation.test.js +++ b/test/resolveLocation.test.js @@ -13,12 +13,12 @@ test('resolveLocation', async t => { await t.test('a valid [lon, lat] Array returns a feature match', t => { const location = [0, 0]; const result = loco.resolveLocation(location); - assert.notEqual(result, null); + assert.ok(result instanceof Object); assert.equal(result.type, 'point'); assert.equal(result.location, location); - assert.equal(typeof result.feature, 'object'); // result includes a `feature` + assert.ok(result.feature instanceof Object); // result includes a `feature` assert.equal(result.feature.id, '[0,0]'); // feature has an `id` - assert.equal(typeof result.feature.properties, 'object'); // feature has `properties` + assert.ok(result.feature.properties instanceof Object); // feature has `properties` assert.equal(result.feature.properties.id, '[0,0]'); // properties has an `id` property assert.equal(result.feature.properties.area, 1963.5); // area = Pi * 25 * 25 }); @@ -26,12 +26,12 @@ test('resolveLocation', async t => { await t.test('a valid [lon, lat, radius] Array returns a feature match', t => { const location = [0, 0, 100]; const result = loco.resolveLocation(location); - assert.notEqual(result, null); + assert.ok(result instanceof Object); assert.equal(result.type, 'point'); assert.equal(result.location, location); - assert.equal(typeof result.feature, 'object'); // result includes a `feature` + assert.ok(result.feature instanceof Object); // result includes a `feature` assert.equal(result.feature.id, '[0,0,100]'); // feature has an `id` - assert.equal(typeof result.feature.properties, 'object'); // feature has `properties` + assert.ok(result.feature.properties instanceof Object); // feature has `properties` assert.equal(result.feature.properties.id, '[0,0,100]'); // properties has an `id` property assert.equal(result.feature.properties.area, 31415.93); // area = Pi * 100 * 100 }); @@ -52,12 +52,12 @@ test('resolveLocation', async t => { await t.test('a known `.geojson` filename with id returns a feature match', t => { const location = 'dc_metro.geojson'; const result = loco.resolveLocation(location); - assert.notEqual(result, null); + assert.ok(result instanceof Object); assert.equal(result.type, 'geojson'); assert.equal(result.location, location); - assert.equal(typeof result.feature, 'object'); // result includes a `feature` + assert.ok(result.feature instanceof Object); // result includes a `feature` assert.equal(result.feature.id, 'dc_metro.geojson'); // feature has an `id` - assert.equal(typeof result.feature.properties, 'object'); // feature has `properties` + assert.ok(result.feature.properties instanceof Object); // feature has `properties` assert.equal(result.feature.properties.id, 'dc_metro.geojson'); // properties has an `id` property assert.equal(typeof result.feature.properties.area, 'number'); // properties has a numeric `area` property }); @@ -65,12 +65,12 @@ test('resolveLocation', async t => { await t.test('a known `.geojson` filename with id property returns a feature match', t => { const location = 'philly_metro.geojson'; const result = loco.resolveLocation(location); - assert.notEqual(result, null); + assert.ok(result instanceof Object); assert.equal(result.type, 'geojson'); assert.equal(result.location, location); - assert.equal(typeof result.feature, 'object'); // result includes a `feature` + assert.ok(result.feature instanceof Object); // result includes a `feature` assert.equal(result.feature.id, 'philly_metro.geojson'); // feature has an `id` - assert.equal(typeof result.feature.properties, 'object'); // feature has `properties` + assert.ok(result.feature.properties instanceof Object); // feature has `properties` assert.equal(result.feature.properties.id, 'philly_metro.geojson'); // properties has an `id` property assert.equal(typeof result.feature.properties.area, 'number'); // properties has a numeric `area` property }); @@ -78,12 +78,12 @@ test('resolveLocation', async t => { await t.test('`.geojson` identifiers compare as lowercase', t => { const location = 'PHiLLy_MeTRo.GeoJSoN'; const result = loco.resolveLocation(location); - assert.notEqual(result, null); + assert.ok(result instanceof Object); assert.equal(result.type, 'geojson'); assert.equal(result.location, location); - assert.equal(typeof result.feature, 'object'); // result includes a `feature` + assert.ok(result.feature instanceof Object); // result includes a `feature` assert.equal(result.feature.id, 'philly_metro.geojson'); // feature has an `id` - assert.equal(typeof result.feature.properties, 'object'); // feature has `properties` + assert.ok(result.feature.properties instanceof Object); // feature has `properties` assert.equal(result.feature.properties.id, 'philly_metro.geojson'); // properties has an `id` property assert.equal(typeof result.feature.properties.area, 'number'); // properties has a numeric `area` property }); @@ -104,12 +104,12 @@ test('resolveLocation', async t => { await t.test('a valid country coder feature identifier returns a feature match', t => { const location = 'gb'; const result = loco.resolveLocation(location); - assert.notEqual(result, null); + assert.ok(result instanceof Object); assert.equal(result.type, 'countrycoder'); assert.equal(result.location, location); - assert.equal(typeof result.feature, 'object'); // result includes a `feature` + assert.ok(result.feature instanceof Object); // result includes a `feature` assert.equal(result.feature.id, 'Q145'); // feature has an `id` - assert.equal(typeof result.feature.properties, 'object'); // feature has `properties` + assert.ok(result.feature.properties instanceof Object); // feature has `properties` assert.equal(result.feature.properties.id, 'Q145'); // properties has an `id` property assert.equal(typeof result.feature.properties.area, 'number'); // properties has a numeric `area` property }); diff --git a/test/resolveLocationSet.test.js b/test/resolveLocationSet.test.js index 4c167d4..eacff50 100644 --- a/test/resolveLocationSet.test.js +++ b/test/resolveLocationSet.test.js @@ -19,14 +19,13 @@ test('resolveLocationSet', async t => { await t.test('(non strict mode) empty locationSet defaults to world (Q2)', t => { const locationSet = { }; const result = locoNS.resolveLocationSet(locationSet); - assert.notEqual(result, null); - assert.equal(typeof result, 'object'); + assert.ok(result instanceof Object); assert.equal(result.type, 'locationset'); assert.equal(result.locationSet, locationSet); assert.equal(result.id, '+[Q2]'); - assert.equal(typeof result.feature, 'object'); // result includes a `feature` + assert.ok(result.feature instanceof Object); // result includes a `feature` assert.equal(result.feature.id, 'Q2'); // feature has an `id` - assert.equal(typeof result.feature.properties, 'object'); // feature has `properties` + assert.ok(result.feature.properties instanceof Object); // feature has `properties` assert.equal(result.feature.properties.id, 'Q2'); // properties has an `id` property assert.equal(typeof result.feature.properties.area, 'number'); // properties has a numeric `area` property }); @@ -37,14 +36,13 @@ test('resolveLocationSet', async t => { await t.test('sorts included countrycoder locations', t => { const locationSet = { include: ['013', '005'] }; const result = loco.resolveLocationSet(locationSet); - assert.notEqual(result, null); - assert.equal(typeof result, 'object'); + assert.ok(result instanceof Object); assert.equal(result.type, 'locationset'); assert.equal(result.locationSet, locationSet); assert.equal(result.id, '+[Q18,Q27611]'); - assert.equal(typeof result.feature, 'object'); // result includes a `feature` + assert.ok(result.feature instanceof Object); // result includes a `feature` assert.equal(result.feature.id, '+[Q18,Q27611]'); // feature has an `id` - assert.equal(typeof result.feature.properties, 'object'); // feature has `properties` + assert.ok(result.feature.properties instanceof Object); // feature has `properties` assert.equal(result.feature.properties.id, '+[Q18,Q27611]'); // properties has an `id` property assert.equal(typeof result.feature.properties.area, 'number'); // properties has a numeric `area` property }); @@ -52,14 +50,13 @@ test('resolveLocationSet', async t => { await t.test('sorts excluded countrycoder locations', t => { const locationSet = { include: ['001'], exclude: ['013', '005'] }; const result = loco.resolveLocationSet(locationSet); - assert.notEqual(result, null); - assert.equal(typeof result, 'object'); + assert.ok(result instanceof Object); assert.equal(result.type, 'locationset'); assert.equal(result.locationSet, locationSet); assert.equal(result.id, '+[Q2]-[Q18,Q27611]'); - assert.equal(typeof result.feature, 'object'); // result includes a `feature` + assert.ok(result.feature instanceof Object); // result includes a `feature` assert.equal(result.feature.id, '+[Q2]-[Q18,Q27611]'); // feature has an `id` - assert.equal(typeof result.feature.properties, 'object'); // feature has `properties` + assert.ok(result.feature.properties instanceof Object); // feature has `properties` assert.equal(result.feature.properties.id, '+[Q2]-[Q18,Q27611]'); // properties has an `id` property assert.equal(typeof result.feature.properties.area, 'number'); // properties has a numeric `area` property }); @@ -70,14 +67,13 @@ test('resolveLocationSet', async t => { await t.test('sorts included .geojson locations', t => { const locationSet = { include: ['philly_metro.geojson', 'dc_metro.geojson'] }; const result = loco.resolveLocationSet(locationSet); - assert.notEqual(result, null); - assert.equal(typeof result, 'object'); + assert.ok(result instanceof Object); assert.equal(result.type, 'locationset'); assert.equal(result.locationSet, locationSet); assert.equal(result.id, '+[dc_metro.geojson,philly_metro.geojson]'); - assert.equal(typeof result.feature, 'object'); // result includes a `feature` + assert.ok(result.feature instanceof Object); // result includes a `feature` assert.equal(result.feature.id, '+[dc_metro.geojson,philly_metro.geojson]'); // feature has an `id` - assert.equal(typeof result.feature.properties, 'object'); // feature has `properties` + assert.ok(result.feature.properties instanceof Object); // feature has `properties` assert.equal(result.feature.properties.id, '+[dc_metro.geojson,philly_metro.geojson]'); // properties has an `id` property assert.equal(typeof result.feature.properties.area, 'number'); // properties has a numeric `area` property }); @@ -85,14 +81,13 @@ test('resolveLocationSet', async t => { await t.test('sorts excluded .geojson locations', t => { const locationSet = { include: ['001'], exclude: ['philly_metro.geojson', 'dc_metro.geojson'] }; const result = loco.resolveLocationSet(locationSet); - assert.notEqual(result, null); - assert.equal(typeof result, 'object'); + assert.ok(result instanceof Object); assert.equal(result.type, 'locationset'); assert.equal(result.locationSet, locationSet); assert.equal(result.id, '+[Q2]-[dc_metro.geojson,philly_metro.geojson]'); - assert.equal(typeof result.feature, 'object'); // result includes a `feature` + assert.ok(result.feature instanceof Object); // result includes a `feature` assert.equal(result.feature.id, '+[Q2]-[dc_metro.geojson,philly_metro.geojson]'); // feature has an `id` - assert.equal(typeof result.feature.properties, 'object'); // feature has `properties` + assert.ok(result.feature.properties instanceof Object); // feature has `properties` assert.equal(result.feature.properties.id, '+[Q2]-[dc_metro.geojson,philly_metro.geojson]'); // properties has an `id` property assert.equal(typeof result.feature.properties.area, 'number'); // properties has a numeric `area` property }); @@ -103,14 +98,13 @@ test('resolveLocationSet', async t => { await t.test('sorts included point locations', t => { const locationSet = { include: [[1, 0], [0, 1], [1, 1], [0, 0]] }; const result = loco.resolveLocationSet(locationSet); - assert.notEqual(result, null); - assert.equal(typeof result, 'object'); + assert.ok(result instanceof Object); assert.equal(result.type, 'locationset'); assert.equal(result.locationSet, locationSet); assert.equal(result.id, '+[[0,0],[0,1],[1,0],[1,1]]'); - assert.equal(typeof result.feature, 'object'); // result includes a `feature` + assert.ok(result.feature instanceof Object); // result includes a `feature` assert.equal(result.feature.id, '+[[0,0],[0,1],[1,0],[1,1]]'); // feature has an `id` - assert.equal(typeof result.feature.properties, 'object'); // feature has `properties` + assert.ok(result.feature.properties instanceof Object); // feature has `properties` assert.equal(result.feature.properties.id, '+[[0,0],[0,1],[1,0],[1,1]]'); // properties has an `id` property assert.equal(typeof result.feature.properties.area, 'number'); // properties has a numeric `area` property }); @@ -118,14 +112,13 @@ test('resolveLocationSet', async t => { await t.test('sorts excluded point locations', t => { const locationSet = { include: ['001'], exclude: [[1, 0], [0, 1], [1, 1], [0, 0]] }; const result = loco.resolveLocationSet(locationSet); - assert.notEqual(result, null); - assert.equal(typeof result, 'object'); + assert.ok(result instanceof Object); assert.equal(result.type, 'locationset'); assert.equal(result.locationSet, locationSet); assert.equal(result.id, '+[Q2]-[[0,0],[0,1],[1,0],[1,1]]'); - assert.equal(typeof result.feature, 'object'); // result includes a `feature` + assert.ok(result.feature instanceof Object); // result includes a `feature` assert.equal(result.feature.id, '+[Q2]-[[0,0],[0,1],[1,0],[1,1]]'); // feature has an `id` - assert.equal(typeof result.feature.properties, 'object'); // feature has `properties` + assert.ok(result.feature.properties instanceof Object); // feature has `properties` assert.equal(result.feature.properties.id, '+[Q2]-[[0,0],[0,1],[1,0],[1,1]]'); // properties has an `id` property assert.equal(typeof result.feature.properties.area, 'number'); // properties has a numeric `area` property }); @@ -140,14 +133,13 @@ test('resolveLocationSet', async t => { await t.test('(non strict mode) ignores included junk locations', t => { const locationSet = { include: ['fake', 'null'] }; const result = locoNS.resolveLocationSet(locationSet); - assert.notEqual(result, null); - assert.equal(typeof result, 'object'); + assert.ok(result instanceof Object); assert.equal(result.type, 'locationset'); assert.equal(result.locationSet, locationSet); assert.equal(result.id, '+[Q2]'); - assert.equal(typeof result.feature, 'object'); // result includes a `feature` + assert.ok(result.feature instanceof Object); // result includes a `feature` assert.equal(result.feature.id, 'Q2'); // feature has an `id` - assert.equal(typeof result.feature.properties, 'object'); // feature has `properties` + assert.ok(result.feature.properties instanceof Object); // feature has `properties` assert.equal(result.feature.properties.id, 'Q2'); // properties has an `id` property assert.equal(typeof result.feature.properties.area, 'number'); // properties has a numeric `area` property }); @@ -160,14 +152,13 @@ test('resolveLocationSet', async t => { await t.test('(non strict mode) ignores excluded junk locations', t => { const locationSet = { include: ['001'], exclude: ['fake', 'null'] }; const result = locoNS.resolveLocationSet(locationSet); - assert.notEqual(result, null); - assert.equal(typeof result, 'object'); + assert.ok(result instanceof Object); assert.equal(result.type, 'locationset'); assert.equal(result.locationSet, locationSet); assert.equal(result.id, '+[Q2]'); - assert.equal(typeof result.feature, 'object'); // result includes a `feature` + assert.ok(result.feature instanceof Object); // result includes a `feature` assert.equal(result.feature.id, 'Q2'); // feature has an `id` - assert.equal(typeof result.feature.properties, 'object'); // feature has `properties` + assert.ok(result.feature.properties instanceof Object); // feature has `properties` assert.equal(result.feature.properties.id, 'Q2'); // properties has an `id` property assert.equal(typeof result.feature.properties.area, 'number'); // properties has a numeric `area` property }); @@ -175,14 +166,13 @@ test('resolveLocationSet', async t => { await t.test('sorts included countrycoder < geojson < point', t => { const locationSet = { include: ['philly_metro.geojson', [0,0], 'ca'] }; const result = loco.resolveLocationSet(locationSet); - assert.notEqual(result, null); - assert.equal(typeof result, 'object'); + assert.ok(result instanceof Object); assert.equal(result.type, 'locationset'); assert.equal(result.locationSet, locationSet); assert.equal(result.id, '+[Q16,philly_metro.geojson,[0,0]]'); - assert.equal(typeof result.feature, 'object'); // result includes a `feature` + assert.ok(result.feature instanceof Object); // result includes a `feature` assert.equal(result.feature.id, '+[Q16,philly_metro.geojson,[0,0]]'); // feature has an `id` - assert.equal(typeof result.feature.properties, 'object'); // feature has `properties` + assert.ok(result.feature.properties instanceof Object); // feature has `properties` assert.equal(result.feature.properties.id, '+[Q16,philly_metro.geojson,[0,0]]'); // properties has an `id` property assert.equal(typeof result.feature.properties.area, 'number'); // properties has a numeric `area` property }); @@ -190,14 +180,13 @@ test('resolveLocationSet', async t => { await t.test('sorts excluded countrycoder < geojson < point', t => { const locationSet = { include: ['001'], exclude: ['philly_metro.geojson', [0,0], 'ca'] }; const result = loco.resolveLocationSet(locationSet); - assert.notEqual(result, null); - assert.equal(typeof result, 'object'); + assert.ok(result instanceof Object); assert.equal(result.type, 'locationset'); assert.equal(result.locationSet, locationSet); assert.equal(result.id, '+[Q2]-[Q16,philly_metro.geojson,[0,0]]'); - assert.equal(typeof result.feature, 'object'); // result includes a `feature` + assert.ok(result.feature instanceof Object); // result includes a `feature` assert.equal(result.feature.id, '+[Q2]-[Q16,philly_metro.geojson,[0,0]]'); // feature has an `id` - assert.equal(typeof result.feature.properties, 'object'); // feature has `properties` + assert.ok(result.feature.properties instanceof Object); // feature has `properties` assert.equal(result.feature.properties.id, '+[Q2]-[Q16,philly_metro.geojson,[0,0]]'); // properties has an `id` property assert.equal(typeof result.feature.properties.area, 'number'); // properties has a numeric `area` property }); diff --git a/test/validateLocation.test.js b/test/validateLocation.test.js index 7c06302..1348b98 100644 --- a/test/validateLocation.test.js +++ b/test/validateLocation.test.js @@ -14,7 +14,7 @@ test('validateLocation', async t => { await t.test('a valid [lon, lat] array returns a "point" result', t => { [[0, 0], [-180, -90], [180, -90], [180, 90]].forEach(val => { const result = loco.validateLocation(val); - assert.equal(typeof result, 'object'); + assert.ok(result instanceof Object); assert.equal(result.type, 'point'); assert.equal(result.location, val); assert.equal(result.id, '[' + val.toString() + ']'); @@ -24,7 +24,7 @@ test('validateLocation', async t => { await t.test('a valid [lon, lat, radius] array returns a "point" result', t => { [[0, 0, 20], [-180, -90, 20], [180, -90, 20], [180, 90, 20]].forEach(val => { const result = loco.validateLocation(val); - assert.equal(typeof result, 'object'); + assert.ok(result instanceof Object); assert.equal(result.type, 'point'); assert.equal(result.location, val); assert.equal(result.id, '[' + val.toString() + ']'); @@ -65,7 +65,7 @@ test('validateLocation', async t => { await t.test('a valid `.geojson` identifier returns a "geojson" result', t => { ['philly_metro.geojson', 'dc_metro.geojson'].forEach(val => { const result = loco.validateLocation(val); - assert.equal(typeof result, 'object'); + assert.ok(result instanceof Object); assert.equal(result.type, 'geojson'); assert.equal(result.location, val); assert.equal(result.id, val); @@ -84,7 +84,7 @@ test('validateLocation', async t => { await t.test('`.geojson` identifiers compare as lowercase', t => { const result = loco.validateLocation('PHiLLy_MeTRo.GeoJSoN'); - assert.equal(typeof result, 'object'); + assert.ok(result instanceof Object); assert.equal(result.type, 'geojson'); assert.equal(result.location, 'PHiLLy_MeTRo.GeoJSoN'); assert.equal(result.id, 'philly_metro.geojson'); @@ -96,7 +96,7 @@ test('validateLocation', async t => { await t.test('a valid country coder identifier returns a "countrycoder" result', t => { ['GB', 'gb', 'gbr', '826', 826, 'Q145', '🇬🇧', 'united kingdom'].forEach(val => { const result = loco.validateLocation(val); - assert.equal(typeof result, 'object'); + assert.ok(result instanceof Object); assert.equal(result.type, 'countrycoder'); assert.equal(result.location, val); assert.equal(result.id, 'Q145'); diff --git a/test/validateLocationSet.test.js b/test/validateLocationSet.test.js index c786086..e1bd086 100644 --- a/test/validateLocationSet.test.js +++ b/test/validateLocationSet.test.js @@ -19,8 +19,7 @@ test('validateLocationSet', async t => { await t.test('(non strict mode) empty locationSet defaults to world (Q2)', t => { const locationSet = { }; const result = locoNS.resolveLocationSet(locationSet); - assert.notEqual(result, null); - assert.equal(typeof result, 'object'); + assert.ok(result instanceof Object); assert.equal(result.type, 'locationset'); assert.equal(result.locationSet, locationSet); assert.equal(result.id, '+[Q2]'); @@ -32,8 +31,7 @@ test('validateLocationSet', async t => { await t.test('sorts included countrycoder locations', t => { const locationSet = { include: ['013', '005'] }; const result = loco.resolveLocationSet(locationSet); - assert.notEqual(result, null); - assert.equal(typeof result, 'object'); + assert.ok(result instanceof Object); assert.equal(result.type, 'locationset'); assert.equal(result.locationSet, locationSet); assert.equal(result.id, '+[Q18,Q27611]'); @@ -47,8 +45,7 @@ test('validateLocationSet', async t => { await t.test('(non strict mode) fake included countrycoder locations are ignored', t => { const locationSet = { include: ['013', 'fake', '005'] }; const result = locoNS.resolveLocationSet(locationSet); - assert.notEqual(result, null); - assert.equal(typeof result, 'object'); + assert.ok(result instanceof Object); assert.equal(result.type, 'locationset'); assert.equal(result.locationSet, locationSet); assert.equal(result.id, '+[Q18,Q27611]'); @@ -57,8 +54,7 @@ test('validateLocationSet', async t => { await t.test('sorts excluded countrycoder locations', t => { const locationSet = { include: ['001'], exclude: ['013', '005'] }; const result = loco.resolveLocationSet(locationSet); - assert.notEqual(result, null); - assert.equal(typeof result, 'object'); + assert.ok(result instanceof Object); assert.equal(result.type, 'locationset'); assert.equal(result.locationSet, locationSet); assert.equal(result.id, '+[Q2]-[Q18,Q27611]'); @@ -72,8 +68,7 @@ test('validateLocationSet', async t => { await t.test('(non strict mode) fake excluded countrycoder locations are ignored', t => { const locationSet = { include: ['001'], exclude: ['013', 'fake', '005'] }; const result = locoNS.resolveLocationSet(locationSet); - assert.notEqual(result, null); - assert.equal(typeof result, 'object'); + assert.ok(result instanceof Object); assert.equal(result.type, 'locationset'); assert.equal(result.locationSet, locationSet); assert.equal(result.id, '+[Q2]-[Q18,Q27611]'); @@ -87,8 +82,7 @@ test('validateLocationSet', async t => { await t.test('(non strict mode) missing include is replaced with world', t => { const locationSet = { exclude: ['013', '005'] }; const result = locoNS.resolveLocationSet(locationSet); - assert.notEqual(result, null); - assert.equal(typeof result, 'object'); + assert.ok(result instanceof Object); assert.equal(result.type, 'locationset'); assert.equal(result.locationSet, locationSet); assert.equal(result.id, '+[Q2]-[Q18,Q27611]'); @@ -100,8 +94,7 @@ test('validateLocationSet', async t => { await t.test('sorts included .geojson locations', t => { const locationSet = { include: ['philly_metro.geojson', 'dc_metro.geojson'] }; const result = loco.resolveLocationSet(locationSet); - assert.notEqual(result, null); - assert.equal(typeof result, 'object'); + assert.ok(result instanceof Object); assert.equal(result.type, 'locationset'); assert.equal(result.locationSet, locationSet); assert.equal(result.id, '+[dc_metro.geojson,philly_metro.geojson]'); @@ -115,8 +108,7 @@ test('validateLocationSet', async t => { await t.test('(non strict mode) fake included .geojson locations are ignored', t => { const locationSet = { include: ['philly_metro.geojson', 'fake.geojson', 'dc_metro.geojson'] }; const result = locoNS.resolveLocationSet(locationSet); - assert.notEqual(result, null); - assert.equal(typeof result, 'object'); + assert.ok(result instanceof Object); assert.equal(result.type, 'locationset'); assert.equal(result.locationSet, locationSet); assert.equal(result.id, '+[dc_metro.geojson,philly_metro.geojson]'); @@ -125,8 +117,7 @@ test('validateLocationSet', async t => { await t.test('sorts excluded .geojson locations', t => { const locationSet = { include: ['001'], exclude: ['philly_metro.geojson', 'dc_metro.geojson'] }; const result = loco.resolveLocationSet(locationSet); - assert.notEqual(result, null); - assert.equal(typeof result, 'object'); + assert.ok(result instanceof Object); assert.equal(result.type, 'locationset'); assert.equal(result.locationSet, locationSet); assert.equal(result.id, '+[Q2]-[dc_metro.geojson,philly_metro.geojson]'); @@ -140,8 +131,7 @@ test('validateLocationSet', async t => { await t.test('(non strict mode) fake excluded .geojson locations are ignored', t => { const locationSet = { include: ['001'], exclude: ['philly_metro.geojson', 'fake.geojson', 'dc_metro.geojson'] }; const result = locoNS.resolveLocationSet(locationSet); - assert.notEqual(result, null); - assert.equal(typeof result, 'object'); + assert.ok(result instanceof Object); assert.equal(result.type, 'locationset'); assert.equal(result.locationSet, locationSet); assert.equal(result.id, '+[Q2]-[dc_metro.geojson,philly_metro.geojson]'); @@ -154,8 +144,7 @@ test('validateLocationSet', async t => { await t.test('sorts included point locations', t => { const locationSet = { include: [[1, 0], [0, 1], [1, 1], [0, 0]] }; const result = loco.resolveLocationSet(locationSet); - assert.notEqual(result, null); - assert.equal(typeof result, 'object'); + assert.ok(result instanceof Object); assert.equal(result.type, 'locationset'); assert.equal(result.locationSet, locationSet); assert.equal(result.id, '+[[0,0],[0,1],[1,0],[1,1]]'); @@ -169,8 +158,7 @@ test('validateLocationSet', async t => { await t.test('(non strict mode) fake included point locations are ignored', t => { const locationSet = { include: [[1, 0], [0, 1], [NaN, NaN], [1, 1], [0, 0]] }; const result = locoNS.resolveLocationSet(locationSet); - assert.notEqual(result, null); - assert.equal(typeof result, 'object'); + assert.ok(result instanceof Object); assert.equal(result.type, 'locationset'); assert.equal(result.locationSet, locationSet); assert.equal(result.id, '+[[0,0],[0,1],[1,0],[1,1]]'); @@ -179,8 +167,7 @@ test('validateLocationSet', async t => { await t.test('sorts excluded point locations', t => { const locationSet = { include: ['001'], exclude: [[1, 0], [0, 1], [1, 1], [0, 0]] }; const result = loco.resolveLocationSet(locationSet); - assert.notEqual(result, null); - assert.equal(typeof result, 'object'); + assert.ok(result instanceof Object); assert.equal(result.type, 'locationset'); assert.equal(result.locationSet, locationSet); assert.equal(result.id, '+[Q2]-[[0,0],[0,1],[1,0],[1,1]]'); @@ -194,8 +181,7 @@ test('validateLocationSet', async t => { await t.test('(non strict mode) fake excluded point locations are ignored', t => { const locationSet = { include: ['001'], exclude: [[1, 0], [0, 1], [NaN, NaN], [1, 1], [0, 0]] }; const result = locoNS.resolveLocationSet(locationSet); - assert.notEqual(result, null); - assert.equal(typeof result, 'object'); + assert.ok(result instanceof Object); assert.equal(result.type, 'locationset'); assert.equal(result.locationSet, locationSet); assert.equal(result.id, '+[Q2]-[[0,0],[0,1],[1,0],[1,1]]'); @@ -206,8 +192,7 @@ test('validateLocationSet', async t => { await t.test('sorts included countrycoder < geojson < point', t => { const locationSet = { include: ['philly_metro.geojson', [0,0], 'ca'] }; const result = loco.resolveLocationSet(locationSet); - assert.notEqual(result, null); - assert.equal(typeof result, 'object'); + assert.ok(result instanceof Object); assert.equal(result.type, 'locationset'); assert.equal(result.locationSet, locationSet); assert.equal(result.id, '+[Q16,philly_metro.geojson,[0,0]]'); @@ -216,8 +201,7 @@ test('validateLocationSet', async t => { await t.test('sorts excluded countrycoder < geojson < point', t => { const locationSet = { include: ['001'], exclude: ['philly_metro.geojson', [0,0], 'ca'] }; const result = loco.resolveLocationSet(locationSet); - assert.notEqual(result, null); - assert.equal(typeof result, 'object'); + assert.ok(result instanceof Object); assert.equal(result.type, 'locationset'); assert.equal(result.locationSet, locationSet); assert.equal(result.id, '+[Q2]-[Q16,philly_metro.geojson,[0,0]]'); @@ -226,8 +210,7 @@ test('validateLocationSet', async t => { await t.test('force lowercase', t => { const locationSet = { include: ['US'], exclude: ['PR'] }; const result = loco.resolveLocationSet(locationSet); - assert.notEqual(result, null); - assert.equal(typeof result, 'object'); + assert.ok(result instanceof Object); assert.equal(result.type, 'locationset'); assert.equal(result.locationSet, locationSet); assert.equal(result.id, '+[Q30]-[Q1183]');