Skip to content

Commit

Permalink
test(toBeAnyGeometry): add robust snapshot tests
Browse files Browse the repository at this point in the history
Adds extensive snapshot testing to address #32.
  • Loading branch information
M-Scott-Lassiter committed Jun 1, 2022
1 parent 472d12d commit 8a6e611
Show file tree
Hide file tree
Showing 2 changed files with 91 additions and 68 deletions.
30 changes: 23 additions & 7 deletions tests/geometries/__snapshots__/toBeAnyGeometry.test.js.snap
Original file line number Diff line number Diff line change
@@ -1,17 +1,33 @@
// Jest Snapshot v1, https://goo.gl/fbAQLP

exports[`Error Snapshot Testing. Throws error: expect({type: 'Point', coordinates: [0, 0]}).not.toBeAnyGeometry 1`] = `
"[2mexpect([22m[31mGeometryObject[39m[2m).not.toBeAnyGeometry()[22m
exports[`Error Snapshot Testing. Throws error: Invalid input to matcher 1`] = `
"[2mexpect([22m[31mGeometryObject[39m[2m).toBeAnyGeometry()[22m
Expected input to not be a valid GeoJSON geometry object.
Argument must be a GeoJSON Geometry object.
Received: [31m{\\"coordinates\\": [0, 0], \\"type\\": \\"Point\\"}[39m"
Received: [31mfalse[39m"
`;

exports[`Error Snapshot Testing. Throws error: expect(false).toBeAnyGeometry 1`] = `
exports[`Error Snapshot Testing. Throws error: Rejects Feature objects 1`] = `
"expect(GeometryObject).toBeAnyGeometry()
Argument must be a GeoJSON Geometry object.
Must have a type property with value 'Point', 'MultiPoint', 'LineString', 'MultiLineString', 'Polygon', 'MultiPolygon', or 'GeometryCollection'.
Received: false"
Received: {\\"geometry\\": {\\"coordinates\\": [102, 0.5], \\"type\\": \\"Point\\"}, \\"type\\": \\"Feature\\"}"
`;

exports[`Error Snapshot Testing. Throws error: Rejects Feature objects 2`] = `
"expect(GeometryObject).toBeAnyGeometry()
Must have a type property with value 'Point', 'MultiPoint', 'LineString', 'MultiLineString', 'Polygon', 'MultiPolygon', or 'GeometryCollection'.
Received: {\\"features\\": [{\\"geometry\\": {\\"coordinates\\": [102, 0.5], \\"type\\": \\"Point\\"}, \\"properties\\": {\\"prop0\\": \\"value0\\"}, \\"type\\": \\"Feature\\"}, {\\"geometry\\": {\\"coordinates\\": [[102, 0], [103, 1], [104, 0], [105, 1]], \\"type\\": \\"LineString\\"}, \\"properties\\": {\\"prop0\\": \\"value0\\", \\"prop1\\": 0}, \\"type\\": \\"Feature\\"}, {\\"geometry\\": {\\"coordinates\\": [[[100, 0], [101, 0], [101, 1], [100, 1], [100, 0]]], \\"type\\": \\"Polygon\\"}, \\"properties\\": {\\"prop0\\": \\"value0\\", \\"prop1\\": {\\"this\\": \\"that\\"}}, \\"type\\": \\"Feature\\"}], \\"type\\": \\"FeatureCollection\\"}"
`;

exports[`Error Snapshot Testing. Throws error: Valid use case passes 1`] = `
"expect(GeometryObject).not.toBeAnyGeometry()
Expected input to not be a valid GeoJSON geometry object.
Received: {\\"coordinates\\": [0, 0], \\"type\\": \\"Point\\"}"
`;
129 changes: 68 additions & 61 deletions tests/geometries/toBeAnyGeometry.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,66 @@
// This test suite also checks it fails with types Feature or FeatureCollection.
// Finally, it tests the unique snapshots.

const feature = {
type: 'Feature',
geometry: {
type: 'Point',
coordinates: [102.0, 0.5]
}
}
const featureCollection = {
type: 'FeatureCollection',
features: [
{
type: 'Feature',
geometry: {
type: 'Point',
coordinates: [102.0, 0.5]
},
properties: {
prop0: 'value0'
}
},
{
type: 'Feature',
geometry: {
type: 'LineString',
coordinates: [
[102.0, 0.0],
[103.0, 1.0],
[104.0, 0.0],
[105.0, 1.0]
]
},
properties: {
prop0: 'value0',
prop1: 0.0
}
},
{
type: 'Feature',
geometry: {
type: 'Polygon',
coordinates: [
[
[100.0, 0.0],
[101.0, 0.0],
[101.0, 1.0],
[100.0, 1.0],
[100.0, 0.0]
]
]
},
properties: {
prop0: 'value0',
prop1: {
this: 'that'
}
}
}
]
}

describe('Valid Use Cases', () => {
test('Expect to pass with GeometryCollection', () => {
const geometryCollection = {
Expand All @@ -27,80 +87,27 @@ describe('Valid Use Cases', () => {

describe('Invalid Use Cases', () => {
test('Expect to fail with Feature', () => {
const feature = {
type: 'Feature',
geometry: {
type: 'Point',
coordinates: [102.0, 0.5]
}
}
expect(feature).not.toBeAnyGeometry()
})

test('Expect to fail with FeatureCollection', () => {
const featureCollection = {
type: 'FeatureCollection',
features: [
{
type: 'Feature',
geometry: {
type: 'Point',
coordinates: [102.0, 0.5]
},
properties: {
prop0: 'value0'
}
},
{
type: 'Feature',
geometry: {
type: 'LineString',
coordinates: [
[102.0, 0.0],
[103.0, 1.0],
[104.0, 0.0],
[105.0, 1.0]
]
},
properties: {
prop0: 'value0',
prop1: 0.0
}
},
{
type: 'Feature',
geometry: {
type: 'Polygon',
coordinates: [
[
[100.0, 0.0],
[101.0, 0.0],
[101.0, 1.0],
[100.0, 1.0],
[100.0, 0.0]
]
]
},
properties: {
prop0: 'value0',
prop1: {
this: 'that'
}
}
}
]
}
expect(featureCollection).not.toBeAnyGeometry()
})
})

describe('Error Snapshot Testing. Throws error:', () => {
test(`expect({type: 'Point', coordinates: [0, 0]}).not.toBeAnyGeometry`, () => {
test('Valid use case passes', () => {
expect(() =>
expect({ type: 'Point', coordinates: [0, 0] }).not.toBeAnyGeometry()
).toThrowErrorMatchingSnapshot()
})
test('expect(false).toBeAnyGeometry', () => {

test('Invalid input to matcher', () => {
expect(() => expect(false).toBeAnyGeometry()).toThrowErrorMatchingSnapshot()
})

test('Rejects Feature objects', () => {
expect(() => expect(feature).toBeAnyGeometry()).toThrowErrorMatchingSnapshot()
expect(() => expect(featureCollection).toBeAnyGeometry()).toThrowErrorMatchingSnapshot()
})
})

0 comments on commit 8a6e611

Please sign in to comment.