Skip to content

Commit

Permalink
test(toBePolygonGeometry): 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 57dc767 commit 1c9df69
Show file tree
Hide file tree
Showing 2 changed files with 106 additions and 7 deletions.
58 changes: 53 additions & 5 deletions tests/geometries/__snapshots__/toBePolygonGeometry.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: 'Polygon', coordinates: 0,0,1,0,0,1,1,0,0,1,0,0}).not.toBePolygonGeometry 1`] = `
"[2mexpect([22m[31mGeometryObject[39m[2m).not.toBePolygonGeometry()[22m
exports[`Error Snapshot Testing. Throws error: Bounding box must be valid 1`] = `
"[2mexpect([22m[31mGeometryObject[39m[2m).toBePolygonGeometry()[22m
Expected input to not be a valid GeoJSON Polygon 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\\": \\"Polygon\\"}"
Received: {\\"bbox\\": [0], \\"coordinates\\": [[[0, 0], [1, 0, 0], [1, 1, 0], [0, 1], [0, 0]]], \\"type\\": \\"Polygon\\"}"
`;

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

exports[`Error Snapshot Testing. Throws error: Has forbidden property: features 1`] = `
"expect(GeometryObject).toBePolygonGeometry()
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\\": \\"Polygon\\"}"
`;

exports[`Error Snapshot Testing. Throws error: Has forbidden property: geometry 1`] = `
"expect(GeometryObject).toBePolygonGeometry()
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\\": \\"Polygon\\"}"
`;

exports[`Error Snapshot Testing. Throws error: expect(false).toBePolygonGeometry() 1`] = `
exports[`Error Snapshot Testing. Throws error: Has forbidden property: properties 1`] = `
"expect(GeometryObject).toBePolygonGeometry()
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\\": \\"Polygon\\"}"
`;

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

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

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

describe('Error Snapshot Testing. Throws error:', () => {
test(`expect({type: 'Polygon', coordinates: ${counterClockwiseBox}}).not.toBePolygonGeometry`, () => {
test('Valid use case passes', () => {
expect(() =>
expect({
type: 'Polygon',
Expand All @@ -632,7 +632,58 @@ describe('Error Snapshot Testing. Throws error:', () => {
).toThrowErrorMatchingSnapshot()
})

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

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

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

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

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

test('Missing coordinates property', () => {
const testPolygon = {
type: 'Polygon'
}
expect(() => expect(testPolygon).toBePolygonGeometry()).toThrowErrorMatchingSnapshot()
})

test('Coordinates not an array', () => {
const testPolygon = {
type: 'Polygon',
coordinates: false
}
expect(() => expect(testPolygon).toBePolygonGeometry()).toThrowErrorMatchingSnapshot()
})
})

0 comments on commit 1c9df69

Please sign in to comment.