Skip to content

Commit

Permalink
test(isValid2DCoordinate): 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 8a6e611 commit ae92f67
Show file tree
Hide file tree
Showing 2 changed files with 44 additions and 8 deletions.
36 changes: 30 additions & 6 deletions tests/coordinates/__snapshots__/isValid2DCoordinate.test.js.snap
Original file line number Diff line number Diff line change
@@ -1,18 +1,42 @@
// Jest Snapshot v1, https://goo.gl/fbAQLP

exports[`Error Snapshot Testing. Throws error: expect([0, 0]).not.isValid3DCoordinate 1`] = `
"[2mexpect([22m[31m[longitude, latitude][39m[2m).not.isValid2DCoordinate()[22m
exports[`Error Snapshot Testing. Throws error: Coordinate latitude must be a number between -90 and 90 1`] = `
"[2mexpect([22m[31m[longitude, latitude][39m[2m).isValid2DCoordinate()[22m
Expected input to not be a two element array with longitude between (-90 to 90),
and latitude between (-180 to 180).
Coordinate latitude must be a number between -90 and 90.
Received: [0, 0]"
Received: [0, 100]"
`;

exports[`Error Snapshot Testing. Throws error: Coordinate longitude must be a number between -180 and 180 1`] = `
"expect([longitude, latitude]).isValid2DCoordinate()
Coordinate longitude must be a number between -180 and 180.
Received: [-256, 0]"
`;

exports[`Error Snapshot Testing. Throws error: Coordinate must be an array of only two elments 1`] = `
"expect([longitude, latitude]).isValid2DCoordinate()
Coordinate must be an array of only two elments.
Received: [0, 0, 733]"
`;

exports[`Error Snapshot Testing. Throws error: expect(false).isValid2DCoordinate() 1`] = `
exports[`Error Snapshot Testing. Throws error: Invalid input to matcher 1`] = `
"expect([longitude, latitude]).isValid2DCoordinate()
Coordinate must be an array of only two elments.
Received: false"
`;

exports[`Error Snapshot Testing. Throws error: Valid use case passes 1`] = `
"expect([longitude, latitude]).not.isValid2DCoordinate()
Expected input to not be a two element array with longitude between (-90 to 90),
and latitude between (-180 to 180).
Received: [0, 0]"
`;
16 changes: 14 additions & 2 deletions tests/coordinates/isValid2DCoordinate.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -122,11 +122,23 @@ describe('Inalid Use Cases', () => {
})

describe('Error Snapshot Testing. Throws error:', () => {
test('expect([0, 0]).not.isValid3DCoordinate', () => {
test('Valid use case passes', () => {
expect(() => expect([0, 0]).not.isValid2DCoordinate()).toThrowErrorMatchingSnapshot()
})

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

test('Coordinate must be an array of only two elments', () => {
expect(() => expect([0, 0, 733]).isValid2DCoordinate()).toThrowErrorMatchingSnapshot()
})

test('Coordinate longitude must be a number between -180 and 180', () => {
expect(() => expect([-256, 0]).isValid2DCoordinate()).toThrowErrorMatchingSnapshot()
})

test('Coordinate latitude must be a number between -90 and 90', () => {
expect(() => expect([0, 100]).isValid2DCoordinate()).toThrowErrorMatchingSnapshot()
})
})

0 comments on commit ae92f67

Please sign in to comment.