Skip to content

Commit

Permalink
test(toBeMultiPolygonGeometry): 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 1c9df69 commit df1c23a
Show file tree
Hide file tree
Showing 2 changed files with 118 additions and 7 deletions.
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: 'MultiPolygon', coordinates: [0,0,1,0,0,1,1,0,0,1,0,0]}).not.toBeMultiPolygonGeometry 1`] = `
"[2mexpect([22m[31mGeometryObject[39m[2m).not.toBeMultiPolygonGeometry()[22m
exports[`Error Snapshot Testing. Throws error: Bounding box must be valid 1`] = `
"[2mexpect([22m[31mGeometryObject[39m[2m).toBeMultiPolygonGeometry()[22m
Expected input to not be a valid GeoJSON MultiPolygon geometry.
Bounding box must be an array of either four or six elments.
Received: {\\"coordinates\\": [[[[0, 0], [1, 0, 0], [1, 1, 0], [0, 1], [0, 0]]]], \\"type\\": \\"MultiPolygon\\"}"
Received: {\\"bbox\\": [0], \\"coordinates\\": [[[[0, 0], [1, 0, 0], [1, 1, 0], [0, 1], [0, 0]]]], \\"type\\": \\"MultiPolygon\\"}"
`;

exports[`Error Snapshot Testing. Throws error: Coordinates not an array 1`] = `
"expect(GeometryObject).toBeMultiPolygonGeometry()
Coordinates property must be an array (appropriately structured by geometry type) with valid GeoJSON coordinates.
Received: {\\"coordinates\\": false, \\"type\\": \\"MultiPolygon\\"}"
`;

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

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

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

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

exports[`Error Snapshot Testing. Throws error: Missing coordinates property 1`] = `
"expect(GeometryObject).toBeMultiPolygonGeometry()
GeoJSON Geometry objects (except GeometryCollection) must contain a 'coordinates' property.
Received: {\\"type\\": \\"MultiPolygon\\"}"
`;

exports[`Error Snapshot Testing. Throws error: Valid use case passes 1`] = `
"expect(GeometryObject).not.toBeMultiPolygonGeometry()
Expected input to not be a valid GeoJSON MultiPolygon geometry.
Received: {\\"coordinates\\": [[[[0, 0], [1, 0, 0], [1, 1, 0], [0, 1], [0, 0]]]], \\"type\\": \\"MultiPolygon\\"}"
`;
67 changes: 65 additions & 2 deletions tests/geometries/toBeMultiPolygonGeometry.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -758,7 +758,7 @@ describe('Inalid Use Cases', () => {
})

describe('Error Snapshot Testing. Throws error:', () => {
test(`expect({type: 'MultiPolygon', coordinates: [${counterClockwiseBox}]}).not.toBeMultiPolygonGeometry`, () => {
test('Valid use case passes', () => {
expect(() =>
expect({
type: 'MultiPolygon',
Expand All @@ -767,7 +767,70 @@ describe('Error Snapshot Testing. Throws error:', () => {
).toThrowErrorMatchingSnapshot()
})

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

test('Has forbidden property: geometry', () => {
const testMultiPolygon = {
type: 'MultiPolygon',
coordinates: [[counterClockwiseBox]],
geometry: null
}
expect(() =>
expect(testMultiPolygon).toBeMultiPolygonGeometry()
).toThrowErrorMatchingSnapshot()
})

test('Has forbidden property: properties', () => {
const testMultiPolygon = {
type: 'MultiPolygon',
coordinates: [[counterClockwiseBox]],
properties: null
}
expect(() =>
expect(testMultiPolygon).toBeMultiPolygonGeometry()
).toThrowErrorMatchingSnapshot()
})

test('Has forbidden property: features', () => {
const testMultiPolygon = {
type: 'MultiPolygon',
coordinates: [[counterClockwiseBox]],
features: null
}
expect(() =>
expect(testMultiPolygon).toBeMultiPolygonGeometry()
).toThrowErrorMatchingSnapshot()
})

test('Bounding box must be valid', () => {
const testMultiPolygon = {
type: 'MultiPolygon',
coordinates: [[counterClockwiseBox]],
bbox: [0]
}
expect(() =>
expect(testMultiPolygon).toBeMultiPolygonGeometry()
).toThrowErrorMatchingSnapshot()
})

test('Missing coordinates property', () => {
const testMultiPolygon = {
type: 'MultiPolygon'
}
expect(() =>
expect(testMultiPolygon).toBeMultiPolygonGeometry()
).toThrowErrorMatchingSnapshot()
})

test('Coordinates not an array', () => {
const testMultiPolygon = {
type: 'MultiPolygon',
coordinates: false
}
expect(() =>
expect(testMultiPolygon).toBeMultiPolygonGeometry()
).toThrowErrorMatchingSnapshot()
})
})

0 comments on commit df1c23a

Please sign in to comment.