Package detail

jest-geojson

Additional Jest matchers for GeoJSON

jest, jest-tests, jest-geojson, geojson

readme

Jest-GeoJSON - GeoJSON Validation Matchers for Jest --- NPM Version Completed and deployed matchers Proposed new matchers Powered by Jest License This project has reached initial release! --- Tests Build codecov Dependency status Vulnerabilities Open Issues Maintained contributions welcome
<summary>Table of Contents</summary> - Purpose - Getting Started - Install as a Dependency - Configure Jest - Configure Typescript - Matchers - Coordiantes - Bounding Boxes - Geometries - Features - Feature Collections - Functional - Advanced Configuration - Load Matchers by Category - Load Specific Matchers - Import the Core Engine - Support Policy - Minimum Supported Jest Version - Node and Operating System - License and Development - Contact

Purpose

Jest-GeoJSON extends the Jest unit testing framework with a comprehensive set of matchers tailored to checking GeoJSON object validity and other geodesy attributes. For example:

const testPoint = {
    type: 'Point',
    coordinates: [25, 10.2]
}

test('Object is valid GeoJSON Point Geometry', () => {
    expect(testPoint).toBePointGeometry()
})

This library DOES NOT create or manipulate GeoJSON. Other tools have done that (and better), such as the venerable Turf.js.

This project complements, not competes with, those tools.

Getting Started

Install as a Dependency

After installing Jest, run:

npm install --save-dev jest-geojson

Configure Jest

Jest will run custom scripts after its environment loads. You can take advantage of that to load all Jest-GeoJSON matchers automatically.

To do so, either create a jest.config.js file:

module.exports = {
    setupFilesAfterEnv: ['jest-geojson/setup/all']
}

or add a key to your package.json:

{
    "name": "myPackageName",
    ...
    "jest": {
        "setupFilesAfterEnv": ["jest-geojson/setup/all"]
    }
}

Configure Typescript

If your editor does not recognize the custom Jest-GeoJSON matchers, add a global.d.ts file to your project with:

import 'jest-geojson'

Then add a files key in your tsconfig.json:

{
  "compilerOptions": {
    ...
  },
  ...
  "files": ["global.d.ts"]
}

Matchers

Jest-GeoJSON organizes matchers by categories. Most correspond to the expected input type passed to expect(). For example, the Coordinates matchers expect a coordinate array, and geometry matchers expect a GeoJSON geometry object.

Functional matchers assess more generic attributes and qualities and many accept multiple input types.

Coordiantes

Bounding Boxes

Geometries

Features


Future

  • [ ] toHaveProperties (array of [property, optional values])

Feature Collections


Future

  • [ ] toContainFeatureTypes (array of feature type strings, optional min count, optional max count)
  • [ ] toContainIDs ([optional unordered array of IDs])
  • [ ] toContainStringIDs
  • [ ] toContainNumericIDs
  • [ ] toContainUniqueIDs
  • [ ] toContainAnyIDs
  • [ ] toContainOnlyIDs ([unordered array of IDs])

Functional


Future

  • [ ] toHave2DBoundingBox
  • [ ] toHave3DBoundingBox
  • [ ] toHaveBoundingBox
  • [ ] toCrossAntimeridian
  • [ ] toIncludePole (Optional 'North' or 'South')
  • [ ] isInHemisphere('North', 'South', 'East', 'West')
  • [ ] toHaveMinPointCount
  • [ ] toHaveMaxPointCount
  • [ ] toHavePointCount (equal/min, optional max)
  • [ ] toHaveMaxPrecision (num decimal places)
  • [ ] toHaveMinPrecision (num decimal places)
  • [ ] toHavePrecision (equal to/min decimal places, optional max decimal places)
  • [ ] toIncludeGeometryTypes (optional array of [Geometry type strings, optional min count, optional max count])
  • [ ] toIncludeForeignMembers (optional array of [members, optional values])
  • [ ] toIncludeAnyCoordinates ([unordered array of points])
  • [ ] toIncludeAllCoordinates ([unordered array of points])
  • [ ] toIncludeOnlyCoordinates
  • [ ] toIncludeOrderedCoordinates (array of [ordered points])
  • [ ] toContain (array of geometry: [single or multi point/line/polygon whose boundaries are all within argument polygon/multipolygon])
  • [ ] isCounterClockwiseWound
  • [ ] isClockwiseWound
  • [ ] isKinked
  • [ ] toBeContainedWithinBBox
  • [ ] toBeContainedWithinPolygon

Advanced Configuration

Load Matchers by Category

You can load matcher subsets if you only need a limited set. Available scipts are:

  • jest-geojson/setup/all
  • jest-geojson/setup/boundingBoxes
  • jest-geojson/setup/coordinates
  • jest-geojson/setup/featureCollections
  • jest-geojson/setup/features
  • jest-geojson/setup/geometries

For example:

module.exports = {
    setupFilesAfterEnv: ['jest-geojson/setup/coordinates']
}

To load more than one matcher set, pass a comma separated list to the setupFilesAfterEnv array:

module.exports = {
    setupFilesAfterEnv: [
        'jest-geojson/setup/featureCollections',
        'jest-geojson/setup/geometries',
        'jest-geojson/setup/features'
    ]
}

Load Specific Matchers

To load only specific matchers, create a new script and import them either one by one or by group. The matcher object contains each matcher grouped by category.

// ./my-custom-load-script.js

const matchers = require('jest-geojson')

expect.extend({ matchers.coordinates.isValidCoordinate }) // Loads single matcher
expect.extend({ matchers.boundingBoxes.isValidBoundingBox }) // Loads single matcher
expect.extend(matchers.geometries) // Loads all matchers in the geometries category

For another example, see the setup script.

Import the Core Engine

The core object contains the functions grouped by category. You can then use these functions elsewhere in your code, or even port Jest-GeoJSON into another testing framework. To import the functions that drive the test matchers:

const core = require('jest-geojson/core')

Support Policy

Minimum Supported Jest Version

This project requires Jest v24.0.0 or newer.

Node and Operating System

The test suite has successfully run on all combinations of:

  • Node Versions Supported
  • Windows Supported Mac Supported Linux Supported

This project supports Long-Term Support, Current, and Maintenance versions of node. Once a version reaches end of life, the CI scripts will no longer support them. Odd Node versions will only receive support while in a current status.

Other Node versions and operating systems might support the library, but the tests have not verified other combinations.

License and Development

Jest-GeoJSON and all other files in this repository are distributed as free and open-source software under the MIT License, © 2022.

Both contributions and bug reports welcome.

Leave a :star2: if you find this project useful!

Contact

Maintained by M. Scott Lassiter.

GitHub Badge Profile Twitter Badge Profile LinkedIn Badge Profile Stackoverflow Badge Profile

changelog

1.6.0 (2022-06-12)

:compass: API Documentation Changes

  • toHaveGeometryCount: improve error messages and description for nested GeometryCollections behavior (01fe745)

:lady_beetle: Bug Fixes

  • toHaveGeometryCount: correct issue where empty collections would fail when provided with a valid range (93dadff), closes #58

:gift: Feature Changes

  • toHaveMaxGeometryCount: add new matcher (8a1f103), closes #47
  • toHaveMinGeometryCount: add new matcher (c71c21a), closes #45

1.5.0 (2022-06-11)

:gift: Feature Changes

  • toHaveGeometryCount: add new matcher (b4bff1c), closes #48

1.4.0 (2022-06-10)

:gift: Feature Changes

  • toBeMultiPolygonWithHole: add new matcher (6668a1b), closes #44
  • toBePolygonWithHole: add new matcher (3eb435c), closes #43
  • add Typescript support for the matchers (602c33b), closes #42

1.3.0 (2022-06-08)

:gift: Feature Changes

  • toHaveNumericID: add new matcher (56e3e4c), closes #38
  • toHaveStringID: add new matcher (cefddd6), closes #37

1.2.0 (2022-06-07)

:gift: Feature Changes

:compass: API Documentation Changes

  • toHaveID: fix documentation typo. (c0f731b)

1.1.0 (2022-06-04)

:gift: Feature Changes

  • toBeValidGeoJSON: add new matcher (bf67420), closes #26

1.0.0 (2022-06-02)

:compass: API Documentation Changes

  • toBeMultiLineStringGeometry: add the min point count error to the JSDoc API (01f6c4b)
  • change JSDoc param types to avoid using GeoJSON unknown types (06ac03a)
  • all: cleanup JSDoc formatting and standardize API examples (300a96d)
  • update JSDoc descriptions of coordinate core functions (f5658f3)
  • update JSDoc organization (7ab7eca)
  • isValidCoordinate: update returns description (70bd43e)
  • isValidCoordinate: update the error and parameter descriptions (7e3e8ed)

:lady_beetle: Bug Fixes

:dart: Test Changes

  • add 'Feature' and 'FeatureCollection' to test list of disallowed geometry type values (f139a09)
  • toBeLineStringGeometry: add a stress test with many points (22df5c7)
  • toBeGeometryCollection: add an unrecognizable geometry to the invalid tests (5c041c6)
  • toBeGeometryCollection: add robust snapshot tests, verify coordinates treated as foreign member (472d12d), closes #32 #33
  • isValid2DBoundingBox: add robust snapshot tests (4363710), closes #32
  • isValid2DCoordinate: add robust snapshot tests (ae92f67), closes #32
  • isValid3DBoundingBox: add robust snapshot tests (a37ec48), closes #32
  • isValid3DCoordinate: add robust snapshot tests (56fbf92), closes #32
  • isValidBoundingBox: add robust snapshot tests (063b94e), closes #32
  • isValidCoordinate: add robust snapshot tests (7b4a804), closes #32
  • toBeAnyGeometry: add robust snapshot tests (8a6e611), closes #32
  • toBeLineStringGeometry: add robust snapshot tests (cfaed46), closes #32
  • toBeMultiLineStringGeometry: add robust snapshot tests (57dc767), closes #32
  • toBeMultiPointGeometry: add robust snapshot tests (36013e1), closes #32
  • toBeMultiPolygonGeometry: add robust snapshot tests (df1c23a), closes #32
  • toBePointGeometry: add robust snapshot tests (fd5c516), closes #32
  • toBePolygonGeometry: add robust snapshot tests (1c9df69), closes #32
  • toBeMultiLineStringGeometry: fix coordinate out of range test that (d6fe2ac)
  • toBeMultiPointGeometry: fix typo in test and core function that was omitting coverage (bc10f4e)
  • isValid2DBoundingBox: fix typo in test descriptions (df94c27)
  • setup the project testing framework (6a95c37)

:gift: Feature Changes

  • isValid2DBoundingBox: add new matcher function (7fe56f3), closes #6
  • isValid2DCoordinate: add new matcher function (527bbc4), closes #1
  • isValid3DCoordinate: add new matcher function (0329231), closes #2
  • isValidCoordinate: add new matcher function (d7e5b70), closes #4
  • isValid3DBoundingBox: add new matcher (6ee8cc6), closes #7
  • isValidBoundingBox: add new matcher (9a8b7ed), closes #8
  • toBeAnyGeometry: add new matcher (ed7c3eb), closes #15
  • toBeFeature: add new matcher (551aa7f), closes #32 #24
  • toBeFeatureCollection: add new matcher (21fe044), closes #25
  • toBeGeometryCollection: add new matcher (63cc919), closes #16
  • toBeLineStringGeometry: add new matcher (54416a5), closes #11
  • toBeMultiLineStringGeometry: add new matcher (3d3a15e), closes #12
  • toBeMultiPointGeometry: add new matcher (9a12752), closes #10
  • toBeMultiPolygonGeometry: add new matcher (41fef3a), closes #14
  • toBePointGeometry: add new matcher (9973afa), closes #9
  • toBePolygonGeometry: add new matcher (3b9d18d), closes #13
  • split package exports into matcher and core functionality (a7340d9), closes #5

:building_construction: Build Changes

  • add conventional-changelog-conventionalcommits as dev dependency (7361d79), closes #3
  • package: add entry points for all, boundingboxes, and coordinates (8c1d312)
  • move release configuration into a separate shareable file (fa6e50d)
  • package: rename matcher loader entry script (5221d6d)
  • setup initial project environment (b468a41)
  • package: update the commitizen config for customized scopes (ac05626)
  • devDependencies: upgrade Jest to v28.1, specify peerDependency at >v24.0.0 (22d1614), closes #30
  • package: upgrade min required Node version to 16 (58a9824)
  • package: upgrade minimum required node version from 10 to 14 to match LTS schedule (1e8a8bb)

1.0.0-beta.16 (2022-06-02)

:gift: Feature Changes

  • toBeFeatureCollection: add new matcher (21fe044), closes #25

1.0.0-beta.15 (2022-06-02)

:gift: Feature Changes

:dart: Test Changes

  • add 'Feature' and 'FeatureCollection' to test list of disallowed geometry type values (f139a09)
  • toBeGeometryCollection: add an unrecognizable geometry to the invalid tests (5c041c6)
  • toBeGeometryCollection: add robust snapshot tests, verify coordinates treated as foreign member (472d12d), closes #32 #33
  • isValid2DBoundingBox: add robust snapshot tests (4363710), closes #32
  • isValid2DCoordinate: add robust snapshot tests (ae92f67), closes #32
  • isValid3DBoundingBox: add robust snapshot tests (a37ec48), closes #32
  • isValid3DCoordinate: add robust snapshot tests (56fbf92), closes #32
  • isValidBoundingBox: add robust snapshot tests (063b94e), closes #32
  • isValidCoordinate: add robust snapshot tests (7b4a804), closes #32
  • toBeAnyGeometry: add robust snapshot tests (8a6e611), closes #32
  • toBeLineStringGeometry: add robust snapshot tests (cfaed46), closes #32
  • toBeMultiLineStringGeometry: add robust snapshot tests (57dc767), closes #32
  • toBeMultiPointGeometry: add robust snapshot tests (36013e1), closes #32
  • toBeMultiPolygonGeometry: add robust snapshot tests (df1c23a), closes #32
  • toBePointGeometry: add robust snapshot tests (fd5c516), closes #32
  • toBePolygonGeometry: add robust snapshot tests (1c9df69), closes #32

1.0.0-beta.14 (2022-06-01)

:lady_beetle: Bug Fixes

1.0.0-beta.13 (2022-05-30)

:gift: Feature Changes

  • toBeGeometryCollection: add new matcher (63cc919), closes #16

1.0.0-beta.12 (2022-05-30)

:gift: Feature Changes

  • toBeAnyGeometry: add new matcher (ed7c3eb), closes #15

:compass: API Documentation Changes

  • all: cleanup JSDoc formatting and standardize API examples (300a96d)

1.0.0-beta.11 (2022-05-30)

:gift: Feature Changes

  • toBeMultiPolygonGeometry: add new matcher (41fef3a), closes #14

1.0.0-beta.10 (2022-05-29)

:compass: API Documentation Changes

  • toBeMultiLineStringGeometry: add the min point count error to the JSDoc API (01f6c4b)

:dart: Test Changes

  • toBeMultiLineStringGeometry: fix coordinate out of range test that (d6fe2ac)
  • toBeMultiPointGeometry: fix typo in test and core function that was omitting coverage (bc10f4e)

:gift: Feature Changes

  • toBePolygonGeometry: add new matcher (3b9d18d), closes #13

1.0.0-beta.9 (2022-05-28)

:dart: Test Changes

  • toBeLineStringGeometry: add a stress test with many points (22df5c7)

:lady_beetle: Bug Fixes

:gift: Feature Changes

  • toBeMultiLineStringGeometry: add new matcher (3d3a15e), closes #12

1.0.0-beta.8 (2022-05-27)

:gift: Feature Changes

  • toBeLineStringGeometry: add new matcher (54416a5), closes #11

:compass: API Documentation Changes

  • change JSDoc param types to avoid using GeoJSON unknown types (06ac03a)

1.0.0-beta.7 (2022-05-26)

:gift: Feature Changes

  • toBeMultiPointGeometry: add new matcher (9a12752), closes #10

1.0.0-beta.6 (2022-05-26)

:gift: Feature Changes

  • toBePointGeometry: add new matcher (9973afa), closes #9

1.0.0-beta.5 (2022-05-25)

:compass: API Documentation Changes

  • update JSDoc descriptions of coordinate core functions (f5658f3)
  • isValidCoordinate: update returns description (70bd43e)
  • isValidCoordinate: update the error and parameter descriptions (7e3e8ed)

:gift: Feature Changes

  • isValidBoundingBox: add new matcher (9a8b7ed), closes #8

1.0.0-beta.4 (2022-05-25)

:building_construction: Build Changes

  • package: add entry points for all, boundingboxes, and coordinates (8c1d312)

:gift: Feature Changes

  • isValid2DBoundingBox: add new matcher function (7fe56f3), closes #6
  • isValid3DBoundingBox: add new matcher (6ee8cc6), closes #7

:dart: Test Changes

  • isValid2DBoundingBox: fix typo in test descriptions (df94c27)

:compass: API Documentation Changes

  • update JSDoc organization (7ab7eca)

1.0.0-beta.3 (2022-05-24)

:gift: Feature Changes

  • split package exports into matcher and core functionality (a7340d9), closes #5

1.0.0-beta.2 (2022-05-24)

:building_construction: Build Changes

  • move release configuration into a separate shareable file (fa6e50d)
  • package: update the commitizen config for customized scopes (ac05626)

:gift: Feature Changes

  • isValidCoordinate: add new matcher function (d7e5b70), closes #4

1.0.0-beta.1 (2022-05-19)

:dart: Test Changes

  • setup the project testing framework (6a95c37)

:gift: Feature Changes

  • isValid2DCoordinate: add new matcher function (527bbc4), closes #1
  • isValid3DCoordinate: add new matcher function (0329231), closes #2

:building_construction: Build Changes

  • add conventional-changelog-conventionalcommits as dev dependency (7361d79), closes #3
  • setup initial project environment (b468a41)