Skip to content

Commit

Permalink
test(toBeGeometryCollection): add robust snapshot tests, verify coord…
Browse files Browse the repository at this point in the history
…inates treated as foreign member

Adds extensive snapshot testing to address #32. Additionally added tests verifying that a
"coordinates" member would get treated as a foreign member. No behavior had to change in the core
function, but now this edge case is verified with testing.

Resolves: #33
  • Loading branch information
M-Scott-Lassiter committed Jun 1, 2022
1 parent df1c23a commit 472d12d
Show file tree
Hide file tree
Showing 2 changed files with 136 additions and 8 deletions.
58 changes: 53 additions & 5 deletions tests/geometries/__snapshots__/toBeGeometryCollection.test.js.snap
Original file line number Diff line number Diff line change
@@ -1,17 +1,65 @@
// Jest Snapshot v1, https://goo.gl/fbAQLP

exports[`Error Snapshot Testing. Throws error: expect({type: 'GeometryCollection', geometries: []}).not.toBeGeometryCollection 1`] = `
"[2mexpect([22m[31mGeometryObject[39m[2m).not.toBeGeometryCollection()[22m
exports[`Error Snapshot Testing. Throws error: Bounding box must be valid 1`] = `
"[2mexpect([22m[31mGeometryObject[39m[2m).toBeGeometryCollection()[22m
Expected input to not be a valid GeoJSON GeometryCollection object.
Bounding box must be an array of either four or six elments.
Received: {\\"geometries\\": [], \\"type\\": \\"GeometryCollection\\"}"
Received: {\\"bbox\\": [0], \\"geometries\\": [], \\"type\\": \\"GeometryCollection\\"}"
`;

exports[`Error Snapshot Testing. Throws error: Geometries not an array 1`] = `
"expect(GeometryObject).toBeGeometryCollection()
Geometries property must be an array of valid GeoJSON geometry objects.
Received: {\\"geometries\\": false, \\"type\\": \\"GeometryCollection\\"}"
`;

exports[`Error Snapshot Testing. Throws error: Has forbidden property: features 1`] = `
"expect(GeometryObject).toBeGeometryCollection()
GeoJSON Geometry objects are forbidden from having a property 'features'.
Received: {\\"features\\": null, \\"geometries\\": [], \\"type\\": \\"GeometryCollection\\"}"
`;

exports[`Error Snapshot Testing. Throws error: Has forbidden property: geometry 1`] = `
"expect(GeometryObject).toBeGeometryCollection()
GeoJSON Geometry objects are forbidden from having a property 'geometry'.
Received: {\\"geometries\\": [], \\"geometry\\": null, \\"type\\": \\"GeometryCollection\\"}"
`;

exports[`Error Snapshot Testing. Throws error: expect(false).toBeGeometryCollection() 1`] = `
exports[`Error Snapshot Testing. Throws error: Has forbidden property: properties 1`] = `
"expect(GeometryObject).toBeGeometryCollection()
GeoJSON Geometry objects are forbidden from having a property 'properties'.
Received: {\\"geometries\\": [], \\"properties\\": null, \\"type\\": \\"GeometryCollection\\"}"
`;

exports[`Error Snapshot Testing. Throws error: Invalid input to matcher 1`] = `
"expect(GeometryObject).toBeGeometryCollection()
Must have a type property with value 'GeometryCollection'.
Received: false"
`;

exports[`Error Snapshot Testing. Throws error: Missing geometries property 1`] = `
"expect(GeometryObject).toBeGeometryCollection()
GeoJSON GeometryCollection must contain a 'geometries' with an array of GeoJSON geometries.
Received: {\\"type\\": \\"GeometryCollection\\"}"
`;

exports[`Error Snapshot Testing. Throws error: Valid use case passes 1`] = `
"expect(GeometryObject).not.toBeGeometryCollection()
Expected input to not be a valid GeoJSON GeometryCollection object.
Received: {\\"geometries\\": [], \\"type\\": \\"GeometryCollection\\"}"
`;
86 changes: 83 additions & 3 deletions tests/geometries/toBeGeometryCollection.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -280,6 +280,23 @@ describe('Valid Use Cases', () => {
expect(testGeometryCollection).toBeAnyGeometry()
})
})

describe('Coordinates Treated as Foreign Member:', () => {
test.each([[0, 0], false, {}, 2, 'Coordinate String'])('coordinates: %p', (input) => {
const testGeometryCollection = {
type: 'GeometryCollection',
geometries: [
{
type: 'Point',
coordinates: [0, 0]
}
],
coordinates: input
}
expect(testGeometryCollection).toBeGeometryCollection()
expect(testGeometryCollection).toBeAnyGeometry()
})
})
})

describe('Invalid Use Cases', () => {
Expand Down Expand Up @@ -391,7 +408,7 @@ describe('Invalid Use Cases', () => {
})
})

describe('Expect to fail with coordinates array of empty arrays:', () => {
describe('Expect to fail with geometries array of empty arrays:', () => {
test.each([...emptyArrays])('coordinates: [%p]', (input) => {
const testGeometryCollection = {
type: 'GeometryCollection',
Expand Down Expand Up @@ -522,13 +539,76 @@ describe('Invalid Use Cases', () => {
})

describe('Error Snapshot Testing. Throws error:', () => {
test(`expect({type: 'GeometryCollection', geometries: []}).not.toBeGeometryCollection`, () => {
test('Valid use case passes', () => {
expect(() =>
expect({ type: 'GeometryCollection', geometries: [] }).not.toBeGeometryCollection()
).toThrowErrorMatchingSnapshot()
})

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

test('Has forbidden property: geometry', () => {
const testGeometryCollection = {
type: 'GeometryCollection',
geometries: [],
geometry: null
}
expect(() =>
expect(testGeometryCollection).toBeGeometryCollection()
).toThrowErrorMatchingSnapshot()
})

test('Has forbidden property: properties', () => {
const testGeometryCollection = {
type: 'GeometryCollection',
geometries: [],
properties: null
}
expect(() =>
expect(testGeometryCollection).toBeGeometryCollection()
).toThrowErrorMatchingSnapshot()
})

test('Has forbidden property: features', () => {
const testGeometryCollection = {
type: 'GeometryCollection',
geometries: [],
features: null
}
expect(() =>
expect(testGeometryCollection).toBeGeometryCollection()
).toThrowErrorMatchingSnapshot()
})

test('Bounding box must be valid', () => {
const testGeometryCollection = {
type: 'GeometryCollection',
geometries: [],
bbox: [0]
}
expect(() =>
expect(testGeometryCollection).toBeGeometryCollection()
).toThrowErrorMatchingSnapshot()
})

test('Missing geometries property', () => {
const testGeometryCollection = {
type: 'GeometryCollection'
}
expect(() =>
expect(testGeometryCollection).toBeGeometryCollection()
).toThrowErrorMatchingSnapshot()
})

test('Geometries not an array', () => {
const testGeometryCollection = {
type: 'GeometryCollection',
geometries: false
}
expect(() =>
expect(testGeometryCollection).toBeGeometryCollection()
).toThrowErrorMatchingSnapshot()
})
})

0 comments on commit 472d12d

Please sign in to comment.