Skip to content

Commit

Permalink
Use instanceof checks for complex types, typeof for builtin types
Browse files Browse the repository at this point in the history
  • Loading branch information
bhousel committed Dec 21, 2023
1 parent d4c70c6 commit 9d36afc
Show file tree
Hide file tree
Showing 4 changed files with 73 additions and 101 deletions.
36 changes: 18 additions & 18 deletions test/resolveLocation.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,25 +13,25 @@ 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
});

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
});
Expand All @@ -52,38 +52,38 @@ 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
});

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
});

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
});
Expand All @@ -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
});
Expand Down
Loading

0 comments on commit 9d36afc

Please sign in to comment.