Skip to content

Commit

Permalink
test(toBeLineStringGeometry): 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 36013e1 commit cfaed46
Show file tree
Hide file tree
Showing 2 changed files with 122 additions and 10 deletions.
58 changes: 53 additions & 5 deletions tests/geometries/__snapshots__/toBeLineStringGeometry.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: 'LineString', coordinates: [[0, 0], [1, 1]]}).not.toBeLineStringGeometry 1`] = `
"[2mexpect([22m[31mGeometryObject[39m[2m).not.toBeLineStringGeometry()[22m
exports[`Error Snapshot Testing. Throws error: Bounding box must be valid 1`] = `
"[2mexpect([22m[31mGeometryObject[39m[2m).toBeLineStringGeometry()[22m
Expected input to not be a valid GeoJSON LineString geometry.
Bounding box must be an array of either four or six elments.
Received: {\\"coordinates\\": [[0, 0], [1, 1]], \\"type\\": \\"LineString\\"}"
Received: {\\"bbox\\": [0], \\"coordinates\\": [[0, 0], [1, 1]], \\"type\\": \\"LineString\\"}"
`;

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

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

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

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

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

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

exports[`Error Snapshot Testing. Throws error: Valid use case passes 1`] = `
"expect(GeometryObject).not.toBeLineStringGeometry()
Expected input to not be a valid GeoJSON LineString geometry.
Received: {\\"coordinates\\": [[0, 0], [1, 1]], \\"type\\": \\"LineString\\"}"
`;
74 changes: 69 additions & 5 deletions tests/geometries/toBeLineStringGeometry.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -437,22 +437,22 @@ describe('Inalid Use Cases', () => {
[[-10.0, -10.0, 0, 10, 10.0, '200']]
]
test.each(invalidBBoxes)('bbox: %p', (input) => {
const testPoint = {
const testLineString = {
type: 'LineString',
coordinates: [
[0, 0],
[1, 1, 0]
],
bbox: input
}
expect(testPoint).not.toBeLineStringGeometry()
expect(testPoint).not.toBeAnyGeometry()
expect(testLineString).not.toBeLineStringGeometry()
expect(testLineString).not.toBeAnyGeometry()
})
})
})

describe('Error Snapshot Testing. Throws error:', () => {
test(`expect({type: 'LineString', coordinates: [[0, 0], [1, 1]]}).not.toBeLineStringGeometry`, () => {
test('Valid use case passes', () => {
expect(() =>
expect({
type: 'LineString',
Expand All @@ -463,7 +463,71 @@ describe('Error Snapshot Testing. Throws error:', () => {
}).not.toBeLineStringGeometry()
).toThrowErrorMatchingSnapshot()
})
test('expect(false).toBeLineStringGeometry()', () => {

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

test('Has forbidden property: geometry', () => {
const testLineString = {
type: 'LineString',
coordinates: [
[0, 0],
[1, 1]
],
geometry: null
}
expect(() => expect(testLineString).toBeLineStringGeometry()).toThrowErrorMatchingSnapshot()
})

test('Has forbidden property: properties', () => {
const testLineString = {
type: 'LineString',
coordinates: [
[0, 0],
[1, 1]
],
properties: null
}
expect(() => expect(testLineString).toBeLineStringGeometry()).toThrowErrorMatchingSnapshot()
})

test('Has forbidden property: features', () => {
const testLineString = {
type: 'LineString',
coordinates: [
[0, 0],
[1, 1]
],
features: null
}
expect(() => expect(testLineString).toBeLineStringGeometry()).toThrowErrorMatchingSnapshot()
})

test('Bounding box must be valid', () => {
const testLineString = {
type: 'LineString',
coordinates: [
[0, 0],
[1, 1]
],
bbox: [0]
}
expect(() => expect(testLineString).toBeLineStringGeometry()).toThrowErrorMatchingSnapshot()
})

test('Missing coordinates property', () => {
const testLineString = {
type: 'LineString'
}
expect(() => expect(testLineString).toBeLineStringGeometry()).toThrowErrorMatchingSnapshot()
})

test('Coordinates not an array', () => {
const testLineString = {
type: 'LineString',
coordinates: false
}
expect(() => expect(testLineString).toBeLineStringGeometry()).toThrowErrorMatchingSnapshot()
})
})

0 comments on commit cfaed46

Please sign in to comment.