From bf67420c415df5a0762ad428e5ad58faca52e017 Mon Sep 17 00:00:00 2001 From: M-Scott-Lassiter Date: Sat, 4 Jun 2022 09:44:40 -0700 Subject: [PATCH] feat(toBeValidGeoJSON): add new matcher This tests an object to see if it meets validation criteria for any of the seven GeoJSON Geometry types, Features, or FeatureCollections. Creates new setup script and entry point, the test:functional script, updates most of the other test suites to include this matcher as a piggy back. Reorganizes utilities. Updates documentation accordingly. Resolves: #26 --- .cz-config.js | 3 +- CONTRIBUTING.md | 37 +- README.md | 3 +- docs/Core.BoundingBoxes.html | 15 +- docs/Core.Coordinates.html | 15 +- docs/Core.FeatureCollections.html | 15 +- docs/Core.Features.html | 15 +- docs/Core.Geometries.html | 15 +- docs/Core.Utilities.html | 206 +++++++- docs/Core.html | 15 +- docs/Matchers.BoundingBoxes.html | 13 + docs/Matchers.Coordinates.html | 13 + docs/Matchers.FeatureCollections.html | 13 + docs/Matchers.Features.html | 13 + docs/Matchers.Functional.html | 463 ++++++++++++++++++ docs/Matchers.Geometries.html | 15 +- docs/Matchers.html | 16 + ...e_boundingBoxes_valid2DBoundingBox.js.html | 13 + ...e_boundingBoxes_valid3DBoundingBox.js.html | 13 + ...ore_boundingBoxes_validBoundingBox.js.html | 13 + ...core_coordinates_valid2DCoordinate.js.html | 13 + ...core_coordinates_valid3DCoordinate.js.html | 13 + docs/core_coordinates_validCoordinate.js.html | 13 + ...atureCollections_featureCollection.js.html | 13 + docs/core_features_feature.js.html | 13 + docs/core_geometries_anyGeometry.js.html | 15 +- ...core_geometries_geometryCollection.js.html | 15 +- ...core_geometries_lineStringGeometry.js.html | 15 +- ...geometries_multiLineStringGeometry.js.html | 15 +- ...core_geometries_multiPointGeometry.js.html | 15 +- ...re_geometries_multiPolygonGeometry.js.html | 15 +- docs/core_geometries_pointGeometry.js.html | 15 +- docs/core_geometries_polygonGeometry.js.html | 15 +- ...utilities_commonGeometryValidation.js.html | 362 ++++++++++++++ docs/core_utilities_validGeoJSON.js.html | 414 ++++++++++++++++ docs/index.html | 22 +- ...boundingBoxes_isValid2DBoundingBox.js.html | 13 + ...boundingBoxes_isValid3DBoundingBox.js.html | 13 + ...s_boundingBoxes_isValidBoundingBox.js.html | 13 + ...rs_coordinates_isValid2DCoordinate.js.html | 13 + ...rs_coordinates_isValid3DCoordinate.js.html | 13 + ...hers_coordinates_isValidCoordinate.js.html | 13 + ...eCollections_toBeFeatureCollection.js.html | 13 + docs/matchers_features_toBeFeature.js.html | 13 + ...tchers_functional_toBeValidGeoJSON.js.html | 413 ++++++++++++++++ ...atchers_geometries_toBeAnyGeometry.js.html | 13 + ..._geometries_toBeGeometryCollection.js.html | 13 + ..._geometries_toBeLineStringGeometry.js.html | 13 + ...etries_toBeMultiLineStringGeometry.js.html | 13 + ..._geometries_toBeMultiPointGeometry.js.html | 13 + ...eometries_toBeMultiPolygonGeometry.js.html | 13 + ...chers_geometries_toBePointGeometry.js.html | 13 + ...ers_geometries_toBePolygonGeometry.js.html | 13 + docs/typedefinitions.js.html | 19 + package.json | 2 + src/core.js | 4 +- src/core/geometries/anyGeometry.js | 2 +- src/core/geometries/geometryCollection.js | 2 +- src/core/geometries/lineStringGeometry.js | 2 +- .../geometries/multiLineStringGeometry.js | 2 +- src/core/geometries/multiPointGeometry.js | 2 +- src/core/geometries/multiPolygonGeometry.js | 2 +- src/core/geometries/pointGeometry.js | 2 +- src/core/geometries/polygonGeometry.js | 2 +- .../commonGeometryValidation.js} | 2 +- src/core/utilities/validGeoJSON.js | 128 +++++ src/matchers.js | 4 + src/matchers/functional/toBeValidGeoJSON.js | 127 +++++ src/setup/all.js | 1 + src/setup/functional.js | 10 + src/typedefinitions.js | 6 + .../isValid2DBoundingBox.test.js | 2 + .../isValid3DBoundingBox.test.js | 2 + tests/coordinates/isValid2DCoordinate.test.js | 2 + tests/coordinates/isValid3DCoordinate.test.js | 2 + tests/core.test.js | 4 + .../toBeFeatureCollection.test.js | 37 ++ tests/features/toBeFeature.test.js | 40 ++ .../toBeValidGeoJSON.test.js.snap | 17 + tests/functional/toBeValidGeoJSON.test.js | 74 +++ tests/geometries/toBeAnyGeometry.test.js | 22 +- .../geometries/toBeGeometryCollection.test.js | 36 ++ .../geometries/toBeLineStringGeometry.test.js | 20 + .../toBeMultiLineStringGeometry.test.js | 20 + .../geometries/toBeMultiPointGeometry.test.js | 16 + .../toBeMultiPolygonGeometry.test.js | 42 ++ tests/geometries/toBePointGeometry.test.js | 17 + tests/geometries/toBePolygonGeometry.test.js | 36 ++ tests/matchers.test.js | 12 +- 89 files changed, 3169 insertions(+), 79 deletions(-) create mode 100644 docs/Matchers.Functional.html create mode 100644 docs/core_utilities_commonGeometryValidation.js.html create mode 100644 docs/core_utilities_validGeoJSON.js.html create mode 100644 docs/matchers_functional_toBeValidGeoJSON.js.html rename src/core/{utilities.js => utilities/commonGeometryValidation.js} (97%) create mode 100644 src/core/utilities/validGeoJSON.js create mode 100644 src/matchers/functional/toBeValidGeoJSON.js create mode 100644 src/setup/functional.js create mode 100644 tests/functional/__snapshots__/toBeValidGeoJSON.test.js.snap create mode 100644 tests/functional/toBeValidGeoJSON.test.js diff --git a/.cz-config.js b/.cz-config.js index 5343c1b..46e38c8 100644 --- a/.cz-config.js +++ b/.cz-config.js @@ -16,7 +16,8 @@ const allMatchers = [ { name: 'toBeMultiPointGeometry' }, { name: 'toBeMultiPolygonGeometry' }, { name: 'toBePointGeometry' }, - { name: 'toBePolygonGeometry' } + { name: 'toBePolygonGeometry' }, + { name: 'toBeValidGeoJSON' } ] const documentationScopes = [ diff --git a/CONTRIBUTING.md b/CONTRIBUTING.md index 7541e90..491ec61 100644 --- a/CONTRIBUTING.md +++ b/CONTRIBUTING.md @@ -103,44 +103,31 @@ After installing, you should [run the build script](#building) to verify everyth ### Project Structure -The `src` folder contains all distribution files. - -The `tests` folder contains the Jest scripts used to verify the matchers work as designed. - ``` ├── src │ ├── core +| │ └── │ ├── matchers +| │ └── │ ├── setup | ├── core.js | ├── matchers.js | └── typedefinitions.js ├── tests +| ├── │ ├── core.test.js | └── matchers.test.js ``` -The `core` folder contains the key functionality. - -The `matchers` folder contains the matchers that use core functions. +- `src`: contains all distribution files + - `core`: contains the key functionality used throughout + - `matchers`: contains the matchers powered by the core functions + - `setup`: contains the scripts that install the matchers into the Jest runtime + - `core.js` and `matchers.js`: export a single object containing their categories as object members, each with their respective functions + - `typedefinitions.js`: documents the project's JSDoc type definitions and contains no actual code +- `tests`: the Jest scripts used to verify the matchers work as designed -The `setup` folder contains the scripts that install the matchers into the Jest runtime. `package.json` references these in entry points. - -The `core`, `matchers`, `setup`, and `tests` folder each have the same subfolder structure: - -``` -├── boundingBoxes -├── coordinates -├── features -├── featureCollections -├── functional -├── geometries -└── geometryCollections -``` - -The `core.js` and `matchers.js` consolidate and export their respective elements grouped by folder structure category. When adding a new matcher, refer to the instructions in the comments at the top of these files. - -`typedefinitions.js` document the project's JSDoc type definitions and contains no actual code. +`package.json` contains entry points for `core.js`, `matchers.js`, and each of the loading scripts in `setup`. ### Building @@ -166,7 +153,9 @@ This project provides high working confidence to developers by uses Jest itself ```bash npm run test # Runs all tests and generates coverage report + npm run test: #runs the tests only in that category + npm run watch # Runs tests in watch mode ``` diff --git a/README.md b/README.md index 423d3e3..988a159 100644 --- a/README.md +++ b/README.md @@ -183,11 +183,12 @@ _Future_ ## Functional +- [toBeValidGeoJSON](https://m-scott-lassiter.github.io/jest-geojson/Matchers.Functional.html#.toBeValidGeoJSON) + --- _Future_ -- [ ] toBeValidGeoJSON - [ ] toHave2DBoundingBox - [ ] toHave3DBoundingBox - [ ] toHaveBoundingBox diff --git a/docs/Core.BoundingBoxes.html b/docs/Core.BoundingBoxes.html index c41b8d3..d08abc3 100644 --- a/docs/Core.BoundingBoxes.html +++ b/docs/Core.BoundingBoxes.html @@ -135,6 +135,9 @@

Namespaces

>commonGeometryValidation +
  • + validGeoJSON +
  • Matchers
  • @@ -196,6 +199,16 @@

    Namespaces

    +
  • + Matchers.Functional + +
  • Matchers.Geometries
      @@ -262,7 +275,7 @@

      diff --git a/docs/Core.Coordinates.html b/docs/Core.Coordinates.html index a2191a9..474c168 100644 --- a/docs/Core.Coordinates.html +++ b/docs/Core.Coordinates.html @@ -135,6 +135,9 @@

      Namespaces

      >commonGeometryValidation +
    • + validGeoJSON +
  • Matchers
  • @@ -196,6 +199,16 @@

    Namespaces

    +
  • + Matchers.Functional + +
  • Matchers.Geometries
      @@ -262,7 +275,7 @@

      diff --git a/docs/Core.FeatureCollections.html b/docs/Core.FeatureCollections.html index fb9e42e..0511369 100644 --- a/docs/Core.FeatureCollections.html +++ b/docs/Core.FeatureCollections.html @@ -135,6 +135,9 @@

      Namespaces

      >commonGeometryValidation +
    • + validGeoJSON +
  • Matchers
  • @@ -196,6 +199,16 @@

    Namespaces

    +
  • + Matchers.Functional + +
  • Matchers.Geometries
      @@ -262,7 +275,7 @@

      diff --git a/docs/Core.Features.html b/docs/Core.Features.html index 444f650..6ebbfdf 100644 --- a/docs/Core.Features.html +++ b/docs/Core.Features.html @@ -135,6 +135,9 @@

      Namespaces

      >commonGeometryValidation +
    • + validGeoJSON +
  • Matchers
  • @@ -196,6 +199,16 @@

    Namespaces

    +
  • + Matchers.Functional + +
  • Matchers.Geometries
      @@ -262,7 +275,7 @@

      diff --git a/docs/Core.Geometries.html b/docs/Core.Geometries.html index e6e378c..f409196 100644 --- a/docs/Core.Geometries.html +++ b/docs/Core.Geometries.html @@ -135,6 +135,9 @@

      Namespaces

      >commonGeometryValidation +
    • + validGeoJSON +
  • Matchers
  • @@ -196,6 +199,16 @@

    Namespaces

    +
  • + Matchers.Functional + +
  • Matchers.Geometries
      @@ -262,7 +275,7 @@

      diff --git a/docs/Core.Utilities.html b/docs/Core.Utilities.html index ada81ce..49b1c17 100644 --- a/docs/Core.Utilities.html +++ b/docs/Core.Utilities.html @@ -135,6 +135,9 @@

      Namespaces

      >commonGeometryValidation +
    • + validGeoJSON +
  • Matchers
  • @@ -196,6 +199,16 @@

    Namespaces

    +
  • + Matchers.Functional + +
  • Matchers.Geometries
      @@ -262,7 +275,7 @@

      @@ -287,8 +300,12 @@

      @@ -491,6 +508,189 @@

      Returns:
      boolean + +

      + (static) validGeoJSON(geoObject) → {boolean} +

      + +
      +
      Source:
      +
      + +
      + +
      See:
      +
      + +
      +
      + +
      + This tests an object to see if it meets validation criteria for any of the + seven GeoJSON Geometry types, Features, or FeatureCollections. +
      + +
      Examples
      + +
      point = {
      +    "type": "Point",
      +    "coordinates": [100.0, 0.0]
      +}
      +lineString = {
      +    "type": "LineString",
      +    "coordinates": [
      +        [
      +            [180.0, 40.0],
      +            [180.0, 50.0],
      +            [170.0, 50.0],
      +            [170.0, 40.0],
      +            [180.0, 40.0]
      +        ]
      +    ]
      +}
      +polygon = {
      +    "type": "Polygon",
      +    "coordinates": [
      +        [
      +            [100.0, 0.0],
      +            [101.0, 0.0],
      +            [101.0, 1.0],
      +            [100.0, 1.0],
      +            [100.0, 0.0]
      +        ]
      +    ]
      +}
      +feature = {
      +    "type": "Feature",
      +    "geometry": {
      +        "type": "Point",
      +        "coordinates": [102.0, 0.5]
      +    }
      +}
      +geometryCollection = {
      +    "type": "GeometryCollection",
      +    "geometries": [{
      +        "type": "Point",
      +        "coordinates": [100.0, 0.0]
      +    }, {
      +        "type": "LineString",
      +        "coordinates": [
      +            [101.0, 0.0],
      +            [102.0, 1.0]
      +        ]
      +    }, {
      +        "type": "Polygon",
      +        "coordinates": [
      +            [
      +                [102.0, 2.0],
      +                [103.0, 2.0],
      +                [103.0, 3.0],
      +                [102.0, 3.0],
      +                [102.0, 2.0]
      +            ]
      +        ]
      +    }, {
      +        "type": "Point",
      +        "coordinates": [150.0, 73.0]
      +    }]
      +}
      +
      +// All of these will return true:
      +
      +validGeoJSON(point)
      +validGeoJSON(lineString)
      +validGeoJSON(polygon)
      +validGeoJSON(feature)
      +validGeoJSON(feature.geometry)
      +validGeoJSON(geometryCollection)
      +validGeoJSON(geometryCollection.geometries[1])
      + +
      // All of these throw errors:
      +
      +validGeoJSON(polygon.coordinates)
      +validGeoJSON(geometryCollection.geometries)
      +validGeoJSON([322, -34.549, 0])
      +validGeoJSON({coordinates: [22, -34.549, 22]})
      + +
      Parameters:
      + + + + + + + + + + + + + + + + + + + + + +
      NameTypeDescription
      geoObject + object + + Any GeoJSON Geometry, Feature, or FeatureCollection object +
      + +
      Throws:
      + +
      +
      +
      + Argument must be a GeoJSON Geometry, Feature, or FeatureCollection + object. +
      +
      +
      +
      +
      +
      Type
      +
      + Error +
      +
      +
      +
      +
      + +
      Returns:
      + +
      + True if a valid GeoJSON object. Will throw a specific error if it encounters + a problem. +
      + +
      +
      Type
      +
      + boolean +
      +
      diff --git a/docs/Core.html b/docs/Core.html index ef689b6..a1b9711 100644 --- a/docs/Core.html +++ b/docs/Core.html @@ -135,6 +135,9 @@

      Namespaces

      >commonGeometryValidation +
    • + validGeoJSON +
  • Matchers
  • @@ -196,6 +199,16 @@

    Namespaces

    +
  • + Matchers.Functional + +
  • Matchers.Geometries
      @@ -258,7 +271,7 @@

      Core

      diff --git a/docs/Matchers.BoundingBoxes.html b/docs/Matchers.BoundingBoxes.html index 1258c5b..edb0144 100644 --- a/docs/Matchers.BoundingBoxes.html +++ b/docs/Matchers.BoundingBoxes.html @@ -135,6 +135,9 @@

      Namespaces

      >commonGeometryValidation +
    • + validGeoJSON +
  • Matchers
  • @@ -196,6 +199,16 @@

    Namespaces

    +
  • + Matchers.Functional + +
  • Matchers.Geometries
      diff --git a/docs/Matchers.Coordinates.html b/docs/Matchers.Coordinates.html index 942d399..bd11c91 100644 --- a/docs/Matchers.Coordinates.html +++ b/docs/Matchers.Coordinates.html @@ -135,6 +135,9 @@

      Namespaces

      >commonGeometryValidation +
    • + validGeoJSON +
  • Matchers
  • @@ -196,6 +199,16 @@

    Namespaces

    +
  • + Matchers.Functional + +
  • Matchers.Geometries
      diff --git a/docs/Matchers.FeatureCollections.html b/docs/Matchers.FeatureCollections.html index 943b97c..fb2971e 100644 --- a/docs/Matchers.FeatureCollections.html +++ b/docs/Matchers.FeatureCollections.html @@ -135,6 +135,9 @@

      Namespaces

      >commonGeometryValidation +
    • + validGeoJSON +
  • Matchers
  • @@ -196,6 +199,16 @@

    Namespaces

    +
  • + Matchers.Functional + +
  • Matchers.Geometries
      diff --git a/docs/Matchers.Features.html b/docs/Matchers.Features.html index bd942ef..625c084 100644 --- a/docs/Matchers.Features.html +++ b/docs/Matchers.Features.html @@ -135,6 +135,9 @@

      Namespaces

      >commonGeometryValidation +
    • + validGeoJSON +
  • Matchers
  • @@ -196,6 +199,16 @@

    Namespaces

    +
  • + Matchers.Functional + +
  • Matchers.Geometries
  • Matchers
  • @@ -196,6 +199,16 @@

    Namespaces

    +
  • + Matchers.Functional + +
  • Matchers.Geometries
      @@ -262,7 +275,7 @@

      diff --git a/docs/Matchers.html b/docs/Matchers.html index b90da13..693fb84 100644 --- a/docs/Matchers.html +++ b/docs/Matchers.html @@ -135,6 +135,9 @@

      Namespaces

      >commonGeometryValidation +
    • + validGeoJSON +
  • Matchers
  • @@ -196,6 +199,16 @@

    Namespaces

    +
  • + Matchers.Functional + +
  • Matchers.Geometries
      @@ -304,6 +317,9 @@

      Namespaces

      Features
      +
      Functional
      +
      +
      Geometries
      diff --git a/docs/core_boundingBoxes_valid2DBoundingBox.js.html b/docs/core_boundingBoxes_valid2DBoundingBox.js.html index 1a400ee..5eefd35 100644 --- a/docs/core_boundingBoxes_valid2DBoundingBox.js.html +++ b/docs/core_boundingBoxes_valid2DBoundingBox.js.html @@ -135,6 +135,9 @@

      Namespaces

      >commonGeometryValidation +
    • + validGeoJSON +
  • Matchers
  • @@ -196,6 +199,16 @@

    Namespaces

    +
  • + Matchers.Functional + +
  • Matchers.Geometries
      diff --git a/docs/core_boundingBoxes_valid3DBoundingBox.js.html b/docs/core_boundingBoxes_valid3DBoundingBox.js.html index 9b01389..4fc2cf0 100644 --- a/docs/core_boundingBoxes_valid3DBoundingBox.js.html +++ b/docs/core_boundingBoxes_valid3DBoundingBox.js.html @@ -135,6 +135,9 @@

      Namespaces

      >commonGeometryValidation +
    • + validGeoJSON +
  • Matchers
  • @@ -196,6 +199,16 @@

    Namespaces

    +
  • + Matchers.Functional + +
  • Matchers.Geometries
      diff --git a/docs/core_boundingBoxes_validBoundingBox.js.html b/docs/core_boundingBoxes_validBoundingBox.js.html index 7fbc769..ac92f9a 100644 --- a/docs/core_boundingBoxes_validBoundingBox.js.html +++ b/docs/core_boundingBoxes_validBoundingBox.js.html @@ -135,6 +135,9 @@

      Namespaces

      >commonGeometryValidation +
    • + validGeoJSON +
  • Matchers
  • @@ -196,6 +199,16 @@

    Namespaces

    +
  • + Matchers.Functional + +
  • Matchers.Geometries
      diff --git a/docs/core_coordinates_valid2DCoordinate.js.html b/docs/core_coordinates_valid2DCoordinate.js.html index 5810042..87bd5a2 100644 --- a/docs/core_coordinates_valid2DCoordinate.js.html +++ b/docs/core_coordinates_valid2DCoordinate.js.html @@ -135,6 +135,9 @@

      Namespaces

      >commonGeometryValidation +
    • + validGeoJSON +
  • Matchers
  • @@ -196,6 +199,16 @@

    Namespaces

    +
  • + Matchers.Functional + +
  • Matchers.Geometries
      diff --git a/docs/core_coordinates_valid3DCoordinate.js.html b/docs/core_coordinates_valid3DCoordinate.js.html index 4360ea0..0877a89 100644 --- a/docs/core_coordinates_valid3DCoordinate.js.html +++ b/docs/core_coordinates_valid3DCoordinate.js.html @@ -135,6 +135,9 @@

      Namespaces

      >commonGeometryValidation +
    • + validGeoJSON +
  • Matchers
  • @@ -196,6 +199,16 @@

    Namespaces

    +
  • + Matchers.Functional + +
  • Matchers.Geometries
      diff --git a/docs/core_coordinates_validCoordinate.js.html b/docs/core_coordinates_validCoordinate.js.html index 3158479..9fa1acf 100644 --- a/docs/core_coordinates_validCoordinate.js.html +++ b/docs/core_coordinates_validCoordinate.js.html @@ -135,6 +135,9 @@

      Namespaces

      >commonGeometryValidation +
    • + validGeoJSON +
  • Matchers
  • @@ -196,6 +199,16 @@

    Namespaces

    +
  • + Matchers.Functional + +
  • Matchers.Geometries
      diff --git a/docs/core_featureCollections_featureCollection.js.html b/docs/core_featureCollections_featureCollection.js.html index e7f8f72..7ae68b3 100644 --- a/docs/core_featureCollections_featureCollection.js.html +++ b/docs/core_featureCollections_featureCollection.js.html @@ -135,6 +135,9 @@

      Namespaces

      >commonGeometryValidation +
    • + validGeoJSON +
  • Matchers
  • @@ -196,6 +199,16 @@

    Namespaces

    +
  • + Matchers.Functional + +
  • Matchers.Geometries
      diff --git a/docs/core_features_feature.js.html b/docs/core_features_feature.js.html index ea916b3..87685e9 100644 --- a/docs/core_features_feature.js.html +++ b/docs/core_features_feature.js.html @@ -135,6 +135,9 @@

      Namespaces

      >commonGeometryValidation +
    • + validGeoJSON +
  • Matchers
  • @@ -196,6 +199,16 @@

    Namespaces

    +
  • + Matchers.Functional + +
  • Matchers.Geometries
      diff --git a/docs/core_geometries_anyGeometry.js.html b/docs/core_geometries_anyGeometry.js.html index a22d7a3..faf52ac 100644 --- a/docs/core_geometries_anyGeometry.js.html +++ b/docs/core_geometries_anyGeometry.js.html @@ -135,6 +135,9 @@

      Namespaces

      >commonGeometryValidation +
    • + validGeoJSON +
  • Matchers
  • @@ -196,6 +199,16 @@

    Namespaces

    +
  • + Matchers.Functional + +
  • Matchers.Geometries
      @@ -255,7 +268,7 @@

      core/geometries/anyGeometry.js

      const { multiLineStringGeometry } = require('./multiLineStringGeometry') const { polygonGeometry } = require('./polygonGeometry') const { multiPolygonGeometry } = require('./multiPolygonGeometry') -const { commonGeometryValidation } = require('../utilities') +const { commonGeometryValidation } = require('../utilities/commonGeometryValidation') /** * Verifies an object meets validity requirements for one of the six basic GeoJSON geometry types: diff --git a/docs/core_geometries_geometryCollection.js.html b/docs/core_geometries_geometryCollection.js.html index 312e3d9..5040d9b 100644 --- a/docs/core_geometries_geometryCollection.js.html +++ b/docs/core_geometries_geometryCollection.js.html @@ -135,6 +135,9 @@

      Namespaces

      >commonGeometryValidation +
    • + validGeoJSON +
  • Matchers
  • @@ -196,6 +199,16 @@

    Namespaces

    +
  • + Matchers.Functional + +
  • Matchers.Geometries
      @@ -250,7 +263,7 @@

      core/geometries/geometryCollection.js

      const { anyGeometry } = require('./anyGeometry')
      -const { commonGeometryValidation } = require('../utilities')
      +const { commonGeometryValidation } = require('../utilities/commonGeometryValidation')
       
       /**
        * Verifies an object is a valid GeoJSON GeometryCollection. This object requires a
      diff --git a/docs/core_geometries_lineStringGeometry.js.html b/docs/core_geometries_lineStringGeometry.js.html
      index d2f4dbe..0dc8205 100644
      --- a/docs/core_geometries_lineStringGeometry.js.html
      +++ b/docs/core_geometries_lineStringGeometry.js.html
      @@ -135,6 +135,9 @@ 

      Namespaces

      >commonGeometryValidation +
    • + validGeoJSON +
  • Matchers
  • @@ -196,6 +199,16 @@

    Namespaces

    +
  • + Matchers.Functional + +
  • Matchers.Geometries
      @@ -250,7 +263,7 @@

      core/geometries/lineStringGeometry.js

      const { validCoordinate } = require('../coordinates/validCoordinate')
      -const { commonGeometryValidation } = require('../utilities')
      +const { commonGeometryValidation } = require('../utilities/commonGeometryValidation')
       
       /**
        * Verifies an object is a valid GeoJSON LineString Geometry. This geometry requires a
      diff --git a/docs/core_geometries_multiLineStringGeometry.js.html b/docs/core_geometries_multiLineStringGeometry.js.html
      index 873a9f5..e34d8d8 100644
      --- a/docs/core_geometries_multiLineStringGeometry.js.html
      +++ b/docs/core_geometries_multiLineStringGeometry.js.html
      @@ -135,6 +135,9 @@ 

      Namespaces

      >commonGeometryValidation +
    • + validGeoJSON +
  • Matchers
  • @@ -196,6 +199,16 @@

    Namespaces

    +
  • + Matchers.Functional + +
  • Matchers.Geometries
      @@ -250,7 +263,7 @@

      core/geometries/multiLineStringGeometry.js

      const { validCoordinate } = require('../coordinates/validCoordinate')
      -const { commonGeometryValidation } = require('../utilities')
      +const { commonGeometryValidation } = require('../utilities/commonGeometryValidation')
       
       /**
        * Verifies an object is a valid GeoJSON MultiLineString Geometry. This geometry requires a
      diff --git a/docs/core_geometries_multiPointGeometry.js.html b/docs/core_geometries_multiPointGeometry.js.html
      index f3adca3..77028af 100644
      --- a/docs/core_geometries_multiPointGeometry.js.html
      +++ b/docs/core_geometries_multiPointGeometry.js.html
      @@ -135,6 +135,9 @@ 

      Namespaces

      >commonGeometryValidation +
    • + validGeoJSON +
  • Matchers
  • @@ -196,6 +199,16 @@

    Namespaces

    +
  • + Matchers.Functional + +
  • Matchers.Geometries
      @@ -250,7 +263,7 @@

      core/geometries/multiPointGeometry.js

      const { validCoordinate } = require('../coordinates/validCoordinate')
      -const { commonGeometryValidation } = require('../utilities')
      +const { commonGeometryValidation } = require('../utilities/commonGeometryValidation')
       
       /**
        * Verifies an object is a valid GeoJSON MultiPoint Geometry. This geometry requires a
      diff --git a/docs/core_geometries_multiPolygonGeometry.js.html b/docs/core_geometries_multiPolygonGeometry.js.html
      index 680e060..2b4d7b8 100644
      --- a/docs/core_geometries_multiPolygonGeometry.js.html
      +++ b/docs/core_geometries_multiPolygonGeometry.js.html
      @@ -135,6 +135,9 @@ 

      Namespaces

      >commonGeometryValidation +
    • + validGeoJSON +
  • Matchers
  • @@ -196,6 +199,16 @@

    Namespaces

    +
  • + Matchers.Functional + +
  • Matchers.Geometries
      @@ -250,7 +263,7 @@

      core/geometries/multiPolygonGeometry.js

      const { validCoordinate } = require('../coordinates/validCoordinate')
      -const { commonGeometryValidation } = require('../utilities')
      +const { commonGeometryValidation } = require('../utilities/commonGeometryValidation')
       
       /**
        * Verifies an object is a valid GeoJSON MultiPolygon Geometry. This geometry requires a
      diff --git a/docs/core_geometries_pointGeometry.js.html b/docs/core_geometries_pointGeometry.js.html
      index 72d17b1..85ca74c 100644
      --- a/docs/core_geometries_pointGeometry.js.html
      +++ b/docs/core_geometries_pointGeometry.js.html
      @@ -135,6 +135,9 @@ 

      Namespaces

      >commonGeometryValidation +
    • + validGeoJSON +
  • Matchers
  • @@ -196,6 +199,16 @@

    Namespaces

    +
  • + Matchers.Functional + +
  • Matchers.Geometries
      @@ -250,7 +263,7 @@

      core/geometries/pointGeometry.js

      const { validCoordinate } = require('../coordinates/validCoordinate')
      -const { commonGeometryValidation } = require('../utilities')
      +const { commonGeometryValidation } = require('../utilities/commonGeometryValidation')
       
       /**
        * Verifies an object is a valid GeoJSON Point Geometry. This geometry requires a
      diff --git a/docs/core_geometries_polygonGeometry.js.html b/docs/core_geometries_polygonGeometry.js.html
      index 9db4aa5..6497454 100644
      --- a/docs/core_geometries_polygonGeometry.js.html
      +++ b/docs/core_geometries_polygonGeometry.js.html
      @@ -135,6 +135,9 @@ 

      Namespaces

      >commonGeometryValidation +
    • + validGeoJSON +
  • Matchers
  • @@ -196,6 +199,16 @@

    Namespaces

    +
  • + Matchers.Functional + +
  • Matchers.Geometries
      @@ -250,7 +263,7 @@

      core/geometries/polygonGeometry.js

      const { validCoordinate } = require('../coordinates/validCoordinate')
      -const { commonGeometryValidation } = require('../utilities')
      +const { commonGeometryValidation } = require('../utilities/commonGeometryValidation')
       
       /**
        * Verifies an object is a valid GeoJSON Polygon Geometry. This geometry requires a
      diff --git a/docs/core_utilities_commonGeometryValidation.js.html b/docs/core_utilities_commonGeometryValidation.js.html
      new file mode 100644
      index 0000000..801177e
      --- /dev/null
      +++ b/docs/core_utilities_commonGeometryValidation.js.html
      @@ -0,0 +1,362 @@
      +
      +
      +    
      +        
      +        core/utilities/commonGeometryValidation.js - Documentation
      +
      +        
      +        
      +        
      +        
      +        
      +        
      +        
      +    
      +    
      +        
      +        
      +
      +        
      +
      +        
      +
      +        
      +

      core/utilities/commonGeometryValidation.js

      + +
      +
      +
      const { validBoundingBox } = require('../boundingBoxes/validBoundingBox')
      +
      +/**
      + * This tests an object to see if it meets common required criteria between all GeoJSON
      + * geometry objects.
      + *
      + * @memberof Core.Utilities
      + * @param {object} geometryObject A GeoJSON geometry object to test for common validity requirements
      + * @returns {boolean} True if all common validations passed. Will throw a specific error if it encounters a problem.
      + * @throws {Error} Argument must be a GeoJSON Geometry object.
      + * @throws {Error} Must have a type property with value 'Point', 'MultiPoint', 'LineString', 'MultiLineString', 'Polygon', 'MultiPolygon', or 'GeometryCollection'.
      + * @throws {Error} GeoJSON Geometry objects are forbidden from having a property 'geometry'.
      + * @throws {Error} GeoJSON Geometry objects are forbidden from having a property 'properties'.
      + * @throws {Error} GeoJSON Geometry objects are forbidden from having a property 'features'.
      + * @throws {Error} GeoJSON Geometry objects (except GeometryCollection) must contain a 'coordinates' property.
      + * @throws {Error} Coordinates property must be an array (appropriately structured by geometry type) with valid GeoJSON coordinates.
      + */
      +function commonGeometryValidation(geometryObject) {
      +    if (typeof geometryObject !== 'object') {
      +        throw new Error('Argument must be a GeoJSON Geometry object.')
      +    }
      +
      +    if (
      +        // This statement might seem redundant, but it is used for 'anyGeometry' to pass a useful error message back from the start if it cannot figure
      +        // out what kind of geometry it is supposed to be dealing with.
      +        !(
      +            geometryObject.type === 'Point' ||
      +            geometryObject.type === 'MultiPoint' ||
      +            geometryObject.type === 'LineString' ||
      +            geometryObject.type === 'MultiLineString' ||
      +            geometryObject.type === 'Polygon' ||
      +            geometryObject.type === 'MultiPolygon' ||
      +            geometryObject.type === 'GeometryCollection'
      +        )
      +    ) {
      +        throw new Error(
      +            `Must have a type property with value 'Point', 'MultiPoint', 'LineString', 'MultiLineString', 'Polygon', 'MultiPolygon', or 'GeometryCollection'.`
      +        )
      +    }
      +
      +    if ('geometry' in geometryObject) {
      +        throw new Error(`GeoJSON Geometry objects are forbidden from having a property 'geometry'.`)
      +    }
      +
      +    if ('properties' in geometryObject) {
      +        throw new Error(
      +            `GeoJSON Geometry objects are forbidden from having a property 'properties'.`
      +        )
      +    }
      +
      +    if ('features' in geometryObject) {
      +        throw new Error(`GeoJSON Geometry objects are forbidden from having a property 'features'.`)
      +    }
      +
      +    if ('bbox' in geometryObject) {
      +        validBoundingBox(geometryObject.bbox)
      +    }
      +
      +    // Geometry objects are allowed to have empty arrays as coordinates, however validCoordinate may not.
      +    // If coordinates is an empty array, we're done. Otherwise, check for coordinate validity.
      +    if (geometryObject.type !== 'GeometryCollection') {
      +        if (!('coordinates' in geometryObject)) {
      +            throw new Error(
      +                `GeoJSON Geometry objects (except GeometryCollection) must contain a 'coordinates' property.`
      +            )
      +        }
      +        if (!Array.isArray(geometryObject.coordinates)) {
      +            throw new Error(
      +                'Coordinates property must be an array (appropriately structured by geometry type) with valid GeoJSON coordinates.'
      +            )
      +        }
      +    }
      +    return true
      +}
      +
      +exports.commonGeometryValidation = commonGeometryValidation
      +
      +
      +
      +
      + +
      + + + + + + + + + + diff --git a/docs/core_utilities_validGeoJSON.js.html b/docs/core_utilities_validGeoJSON.js.html new file mode 100644 index 0000000..9043af4 --- /dev/null +++ b/docs/core_utilities_validGeoJSON.js.html @@ -0,0 +1,414 @@ + + + + + core/utilities/validGeoJSON.js - Documentation + + + + + + + + + + + + + + + + + +
      +

      core/utilities/validGeoJSON.js

      + +
      +
      +
      const { anyGeometry } = require('../geometries/anyGeometry')
      +const { feature } = require('../features/feature')
      +const { featureCollection } = require('../featureCollections/featureCollection')
      +
      +/**
      + * This tests an object to see if it meets validation criteria for any of the seven GeoJSON
      + * Geometry types, Features, or FeatureCollections.
      + *
      + * @memberof Core.Utilities
      + * @see https://github.com/M-Scott-Lassiter/jest-geojson/issues/26
      + * @param {object} geoObject Any GeoJSON Geometry, Feature, or FeatureCollection object
      + * @returns {boolean} True if a valid GeoJSON object. Will throw a specific error if it encounters a problem.
      + * @throws {Error} Argument must be a GeoJSON Geometry, Feature, or FeatureCollection object.
      + * @example
      + * point = {
      + *     "type": "Point",
      + *     "coordinates": [100.0, 0.0]
      + * }
      + * lineString = {
      + *     "type": "LineString",
      + *     "coordinates": [
      + *         [
      + *             [180.0, 40.0],
      + *             [180.0, 50.0],
      + *             [170.0, 50.0],
      + *             [170.0, 40.0],
      + *             [180.0, 40.0]
      + *         ]
      + *     ]
      + * }
      + * polygon = {
      + *     "type": "Polygon",
      + *     "coordinates": [
      + *         [
      + *             [100.0, 0.0],
      + *             [101.0, 0.0],
      + *             [101.0, 1.0],
      + *             [100.0, 1.0],
      + *             [100.0, 0.0]
      + *         ]
      + *     ]
      + * }
      + * feature = {
      + *     "type": "Feature",
      + *     "geometry": {
      + *         "type": "Point",
      + *         "coordinates": [102.0, 0.5]
      + *     }
      + * }
      + * geometryCollection = {
      + *     "type": "GeometryCollection",
      + *     "geometries": [{
      + *         "type": "Point",
      + *         "coordinates": [100.0, 0.0]
      + *     }, {
      + *         "type": "LineString",
      + *         "coordinates": [
      + *             [101.0, 0.0],
      + *             [102.0, 1.0]
      + *         ]
      + *     }, {
      + *         "type": "Polygon",
      + *         "coordinates": [
      + *             [
      + *                 [102.0, 2.0],
      + *                 [103.0, 2.0],
      + *                 [103.0, 3.0],
      + *                 [102.0, 3.0],
      + *                 [102.0, 2.0]
      + *             ]
      + *         ]
      + *     }, {
      + *         "type": "Point",
      + *         "coordinates": [150.0, 73.0]
      + *     }]
      + * }
      + *
      + * // All of these will return true:
      + *
      + * validGeoJSON(point)
      + * validGeoJSON(lineString)
      + * validGeoJSON(polygon)
      + * validGeoJSON(feature)
      + * validGeoJSON(feature.geometry)
      + * validGeoJSON(geometryCollection)
      + * validGeoJSON(geometryCollection.geometries[1])
      + * @example
      + * // All of these throw errors:
      + *
      + * validGeoJSON(polygon.coordinates)
      + * validGeoJSON(geometryCollection.geometries)
      + * validGeoJSON([322, -34.549, 0])
      + * validGeoJSON({coordinates: [22, -34.549, 22]})
      + */
      +function validGeoJSON(geoObject) {
      +    if (typeof geoObject !== 'object' || geoObject === null || Array.isArray(geoObject)) {
      +        throw new Error(
      +            'Argument must be a GeoJSON Geometry, Feature, or FeatureCollection object.'
      +        )
      +    }
      +
      +    if (geoObject.type === 'Feature') {
      +        try {
      +            feature(geoObject)
      +            return true
      +        } catch (err) {
      +            throw new Error(err)
      +        }
      +    }
      +
      +    if (geoObject.type === 'FeatureCollection') {
      +        try {
      +            featureCollection(geoObject)
      +            return true
      +        } catch (err) {
      +            throw new Error(err)
      +        }
      +    }
      +
      +    try {
      +        anyGeometry(geoObject)
      +        return true
      +    } catch (err) {
      +        throw new Error(err)
      +    }
      +}
      +
      +exports.validGeoJSON = validGeoJSON
      +
      +
      +
      +
      + +
      + + + + + + + + + + diff --git a/docs/index.html b/docs/index.html index df7d91a..c0551be 100644 --- a/docs/index.html +++ b/docs/index.html @@ -135,6 +135,9 @@

      Namespaces

      >commonGeometryValidation +
    • + validGeoJSON +
  • Matchers
  • @@ -196,6 +199,16 @@

    Namespaces

    +
  • + Matchers.Functional + +
  • Matchers.Geometries
      @@ -614,10 +627,17 @@

      Feature Collections

    • [ ] toContainOnlyIDs ([unordered array of IDs])

    Functional

    +

    Future

      -
    • [ ] toBeValidGeoJSON
    • [ ] toHave2DBoundingBox
    • [ ] toHave3DBoundingBox
    • [ ] toHaveBoundingBox
    • diff --git a/docs/matchers_boundingBoxes_isValid2DBoundingBox.js.html b/docs/matchers_boundingBoxes_isValid2DBoundingBox.js.html index 824e8b4..d3ce6a5 100644 --- a/docs/matchers_boundingBoxes_isValid2DBoundingBox.js.html +++ b/docs/matchers_boundingBoxes_isValid2DBoundingBox.js.html @@ -135,6 +135,9 @@

      Namespaces

      >commonGeometryValidation +
    • + validGeoJSON +
  • Matchers
  • @@ -196,6 +199,16 @@

    Namespaces

    +
  • + Matchers.Functional + +
  • Matchers.Geometries
      diff --git a/docs/matchers_boundingBoxes_isValid3DBoundingBox.js.html b/docs/matchers_boundingBoxes_isValid3DBoundingBox.js.html index 42f3b57..f02335a 100644 --- a/docs/matchers_boundingBoxes_isValid3DBoundingBox.js.html +++ b/docs/matchers_boundingBoxes_isValid3DBoundingBox.js.html @@ -135,6 +135,9 @@

      Namespaces

      >commonGeometryValidation +
    • + validGeoJSON +
  • Matchers
  • @@ -196,6 +199,16 @@

    Namespaces

    +
  • + Matchers.Functional + +
  • Matchers.Geometries
      diff --git a/docs/matchers_boundingBoxes_isValidBoundingBox.js.html b/docs/matchers_boundingBoxes_isValidBoundingBox.js.html index ab0482e..7b2b5c7 100644 --- a/docs/matchers_boundingBoxes_isValidBoundingBox.js.html +++ b/docs/matchers_boundingBoxes_isValidBoundingBox.js.html @@ -135,6 +135,9 @@

      Namespaces

      >commonGeometryValidation +
    • + validGeoJSON +
  • Matchers
  • @@ -196,6 +199,16 @@

    Namespaces

    +
  • + Matchers.Functional + +
  • Matchers.Geometries
      diff --git a/docs/matchers_coordinates_isValid2DCoordinate.js.html b/docs/matchers_coordinates_isValid2DCoordinate.js.html index 6444b91..5523efd 100644 --- a/docs/matchers_coordinates_isValid2DCoordinate.js.html +++ b/docs/matchers_coordinates_isValid2DCoordinate.js.html @@ -135,6 +135,9 @@

      Namespaces

      >commonGeometryValidation +
    • + validGeoJSON +
  • Matchers
  • @@ -196,6 +199,16 @@

    Namespaces

    +
  • + Matchers.Functional + +
  • Matchers.Geometries
      diff --git a/docs/matchers_coordinates_isValid3DCoordinate.js.html b/docs/matchers_coordinates_isValid3DCoordinate.js.html index 5b16464..b936cc0 100644 --- a/docs/matchers_coordinates_isValid3DCoordinate.js.html +++ b/docs/matchers_coordinates_isValid3DCoordinate.js.html @@ -135,6 +135,9 @@

      Namespaces

      >commonGeometryValidation +
    • + validGeoJSON +
  • Matchers
  • @@ -196,6 +199,16 @@

    Namespaces

    +
  • + Matchers.Functional + +
  • Matchers.Geometries
      diff --git a/docs/matchers_coordinates_isValidCoordinate.js.html b/docs/matchers_coordinates_isValidCoordinate.js.html index 9e3ade3..558211b 100644 --- a/docs/matchers_coordinates_isValidCoordinate.js.html +++ b/docs/matchers_coordinates_isValidCoordinate.js.html @@ -135,6 +135,9 @@

      Namespaces

      >commonGeometryValidation +
    • + validGeoJSON +
  • Matchers
  • @@ -196,6 +199,16 @@

    Namespaces

    +
  • + Matchers.Functional + +
  • Matchers.Geometries
      diff --git a/docs/matchers_featureCollections_toBeFeatureCollection.js.html b/docs/matchers_featureCollections_toBeFeatureCollection.js.html index 36649f0..8a620e2 100644 --- a/docs/matchers_featureCollections_toBeFeatureCollection.js.html +++ b/docs/matchers_featureCollections_toBeFeatureCollection.js.html @@ -135,6 +135,9 @@

      Namespaces

      >commonGeometryValidation +
    • + validGeoJSON +
  • Matchers
  • @@ -196,6 +199,16 @@

    Namespaces

    +
  • + Matchers.Functional + +
  • Matchers.Geometries
      diff --git a/docs/matchers_features_toBeFeature.js.html b/docs/matchers_features_toBeFeature.js.html index 18a0725..da040db 100644 --- a/docs/matchers_features_toBeFeature.js.html +++ b/docs/matchers_features_toBeFeature.js.html @@ -135,6 +135,9 @@

      Namespaces

      >commonGeometryValidation +
    • + validGeoJSON +
  • Matchers
  • @@ -196,6 +199,16 @@

    Namespaces

    +
  • + Matchers.Functional + +
  • Matchers.Geometries
      diff --git a/docs/matchers_functional_toBeValidGeoJSON.js.html b/docs/matchers_functional_toBeValidGeoJSON.js.html new file mode 100644 index 0000000..abf625d --- /dev/null +++ b/docs/matchers_functional_toBeValidGeoJSON.js.html @@ -0,0 +1,413 @@ + + + + + matchers/functional/toBeValidGeoJSON.js - Documentation + + + + + + + + + + + + + + + + + +
      +

      matchers/functional/toBeValidGeoJSON.js

      + +
      +
      +
      const { validGeoJSON } = require('../../core/utilities/validGeoJSON')
      +
      +// eslint-disable-next-line jsdoc/require-returns
      +/**
      + * This tests an object to see if it meets validation criteria for any of the seven GeoJSON
      + * Geometry types, Features, or FeatureCollections.
      + *
      + *
      + * @memberof Matchers.Functional
      + * @see https://github.com/M-Scott-Lassiter/jest-geojson/issues/26
      + * @param {object} geoObject Any GeoJSON Geometry, Feature, or FeatureCollection object
      + * @example
      + * point = {
      + *     "type": "Point",
      + *     "coordinates": [100.0, 0.0]
      + * }
      + * lineString = {
      + *     "type": "LineString",
      + *     "coordinates": [
      + *         [
      + *             [180.0, 40.0],
      + *             [180.0, 50.0],
      + *             [170.0, 50.0],
      + *             [170.0, 40.0],
      + *             [180.0, 40.0]
      + *         ]
      + *     ]
      + * }
      + * polygon = {
      + *     "type": "Polygon",
      + *     "coordinates": [
      + *         [
      + *             [100.0, 0.0],
      + *             [101.0, 0.0],
      + *             [101.0, 1.0],
      + *             [100.0, 1.0],
      + *             [100.0, 0.0]
      + *         ]
      + *     ]
      + * }
      + * feature = {
      + *     "type": "Feature",
      + *     "geometry": {
      + *         "type": "Point",
      + *         "coordinates": [102.0, 0.5]
      + *     }
      + * }
      + * geometryCollection = {
      + *     "type": "GeometryCollection",
      + *     "geometries": [{
      + *         "type": "Point",
      + *         "coordinates": [100.0, 0.0]
      + *     }, {
      + *         "type": "LineString",
      + *         "coordinates": [
      + *             [101.0, 0.0],
      + *             [102.0, 1.0]
      + *         ]
      + *     }, {
      + *         "type": "Polygon",
      + *         "coordinates": [
      + *             [
      + *                 [102.0, 2.0],
      + *                 [103.0, 2.0],
      + *                 [103.0, 3.0],
      + *                 [102.0, 3.0],
      + *                 [102.0, 2.0]
      + *             ]
      + *         ]
      + *     }, {
      + *         "type": "Point",
      + *         "coordinates": [150.0, 73.0]
      + *     }]
      + * }
      + *
      + * test('Object is valid GeoJSON Feature', () => {
      + *      expect(point).toBeValidGeoJSON()
      + *      expect(lineString).toBeValidGeoJSON()
      + *      expect(polygon).toBeValidGeoJSON()
      + *      expect(feature).toBeValidGeoJSON()
      + *      expect(feature.geometry).toBeValidGeoJSON()
      + *      expect(geometryCollection).toBeValidGeoJSON()
      + *      expect(geometryCollection.geometries[1]).toBeValidGeoJSON()
      + * })
      + * @example
      + * test('Object is NOT valid GeoJSON Geometry Object', () => {
      + *      expect(polygon.coordinates).not.toBeValidGeoJSON()
      + *      expect(geometryCollection.geometries).toBeValidGeoJSON()
      + *      expect([322, -34.549, 0]).not.toBeValidGeoJSON()
      + *      expect({coordinates: [22, -34.549, 22]}).not.toBeValidGeoJSON()
      + * })
      + */
      +function toBeValidGeoJSON(geoObject) {
      +    const { printReceived, matcherHint } = this.utils
      +    const passMessage =
      +        // eslint-disable-next-line prefer-template
      +        matcherHint('.not.toBeValidGeoJSON', 'GeoJSONObject', '') +
      +        '\n\n' +
      +        `Expected input to not be a valid GeoJSON Geometry, Feature, or FeatureCollection object.\n\n` +
      +        `Received:  ${printReceived(geoObject)}`
      +
      +    /**
      +     * Combines a custom error message with built in Jest tools to provide a more descriptive error
      +     * meessage to the end user.
      +     *
      +     * @param {string} errorMessage Error message text to return to the user
      +     * @returns {string} Concatenated Jest test result string
      +     */
      +    function failMessage(errorMessage) {
      +        return (
      +            // eslint-disable-next-line prefer-template, no-unused-expressions
      +            matcherHint('.toBeValidGeoJSON', 'GeoJSONObject', '') +
      +            '\n\n' +
      +            `${errorMessage}\n\n` +
      +            `Received:  ${printReceived(geoObject)}`
      +        )
      +    }
      +
      +    try {
      +        validGeoJSON(geoObject)
      +    } catch (err) {
      +        return { pass: false, message: () => failMessage(err.message) }
      +    }
      +    return { pass: true, message: () => passMessage }
      +}
      +
      +exports.toBeValidGeoJSON = toBeValidGeoJSON
      +
      +
      +
      +
      + +
      + + + + + + + + + + diff --git a/docs/matchers_geometries_toBeAnyGeometry.js.html b/docs/matchers_geometries_toBeAnyGeometry.js.html index 0d2e6ba..fedef8e 100644 --- a/docs/matchers_geometries_toBeAnyGeometry.js.html +++ b/docs/matchers_geometries_toBeAnyGeometry.js.html @@ -135,6 +135,9 @@

      Namespaces

      >commonGeometryValidation +
    • + validGeoJSON +
  • Matchers
  • @@ -196,6 +199,16 @@

    Namespaces

    +
  • + Matchers.Functional + +
  • Matchers.Geometries
      diff --git a/docs/matchers_geometries_toBeGeometryCollection.js.html b/docs/matchers_geometries_toBeGeometryCollection.js.html index d83f367..56ed61c 100644 --- a/docs/matchers_geometries_toBeGeometryCollection.js.html +++ b/docs/matchers_geometries_toBeGeometryCollection.js.html @@ -135,6 +135,9 @@

      Namespaces

      >commonGeometryValidation +
    • + validGeoJSON +
  • Matchers
  • @@ -196,6 +199,16 @@

    Namespaces

    +
  • + Matchers.Functional + +
  • Matchers.Geometries
      diff --git a/docs/matchers_geometries_toBeLineStringGeometry.js.html b/docs/matchers_geometries_toBeLineStringGeometry.js.html index f1947b1..8a61822 100644 --- a/docs/matchers_geometries_toBeLineStringGeometry.js.html +++ b/docs/matchers_geometries_toBeLineStringGeometry.js.html @@ -135,6 +135,9 @@

      Namespaces

      >commonGeometryValidation +
    • + validGeoJSON +
  • Matchers
  • @@ -196,6 +199,16 @@

    Namespaces

    +
  • + Matchers.Functional + +
  • Matchers.Geometries
      diff --git a/docs/matchers_geometries_toBeMultiLineStringGeometry.js.html b/docs/matchers_geometries_toBeMultiLineStringGeometry.js.html index deee368..1e169c0 100644 --- a/docs/matchers_geometries_toBeMultiLineStringGeometry.js.html +++ b/docs/matchers_geometries_toBeMultiLineStringGeometry.js.html @@ -135,6 +135,9 @@

      Namespaces

      >commonGeometryValidation +
    • + validGeoJSON +
  • Matchers
  • @@ -196,6 +199,16 @@

    Namespaces

    +
  • + Matchers.Functional + +
  • Matchers.Geometries
      diff --git a/docs/matchers_geometries_toBeMultiPointGeometry.js.html b/docs/matchers_geometries_toBeMultiPointGeometry.js.html index 4e4e1a7..567456f 100644 --- a/docs/matchers_geometries_toBeMultiPointGeometry.js.html +++ b/docs/matchers_geometries_toBeMultiPointGeometry.js.html @@ -135,6 +135,9 @@

      Namespaces

      >commonGeometryValidation +
    • + validGeoJSON +
  • Matchers
  • @@ -196,6 +199,16 @@

    Namespaces

    +
  • + Matchers.Functional + +
  • Matchers.Geometries
      diff --git a/docs/matchers_geometries_toBeMultiPolygonGeometry.js.html b/docs/matchers_geometries_toBeMultiPolygonGeometry.js.html index b1c5397..0699d57 100644 --- a/docs/matchers_geometries_toBeMultiPolygonGeometry.js.html +++ b/docs/matchers_geometries_toBeMultiPolygonGeometry.js.html @@ -135,6 +135,9 @@

      Namespaces

      >commonGeometryValidation +
    • + validGeoJSON +
  • Matchers
  • @@ -196,6 +199,16 @@

    Namespaces

    +
  • + Matchers.Functional + +
  • Matchers.Geometries
      diff --git a/docs/matchers_geometries_toBePointGeometry.js.html b/docs/matchers_geometries_toBePointGeometry.js.html index d507ff5..8a901dc 100644 --- a/docs/matchers_geometries_toBePointGeometry.js.html +++ b/docs/matchers_geometries_toBePointGeometry.js.html @@ -135,6 +135,9 @@

      Namespaces

      >commonGeometryValidation +
    • + validGeoJSON +
  • Matchers
  • @@ -196,6 +199,16 @@

    Namespaces

    +
  • + Matchers.Functional + +
  • Matchers.Geometries
      diff --git a/docs/matchers_geometries_toBePolygonGeometry.js.html b/docs/matchers_geometries_toBePolygonGeometry.js.html index 5ec48d2..7aab9a1 100644 --- a/docs/matchers_geometries_toBePolygonGeometry.js.html +++ b/docs/matchers_geometries_toBePolygonGeometry.js.html @@ -135,6 +135,9 @@

      Namespaces

      >commonGeometryValidation +
    • + validGeoJSON +
  • Matchers
  • @@ -196,6 +199,16 @@

    Namespaces

    +
  • + Matchers.Functional + +
  • Matchers.Geometries
      diff --git a/docs/typedefinitions.js.html b/docs/typedefinitions.js.html index 33dd5fa..5e7fbc7 100644 --- a/docs/typedefinitions.js.html +++ b/docs/typedefinitions.js.html @@ -135,6 +135,9 @@

      Namespaces

      >commonGeometryValidation +
    • + validGeoJSON +
  • Matchers
  • @@ -196,6 +199,16 @@

    Namespaces

    +
  • + Matchers.Functional + +
  • Matchers.Geometries
      @@ -306,6 +319,12 @@

      typedefinitions.js

      * @namespace Matchers.Features */ +/** + * Functional matchers assess more generic attributes and qualities and many accept multiple input types. + * + * @namespace Matchers.Functional + */ + /** * A set of matchers related to validating the seven geometry objects. * diff --git a/package.json b/package.json index 2d14735..ae0c30f 100644 --- a/package.json +++ b/package.json @@ -32,6 +32,7 @@ "./setup/coordinates": "./src/setup/coordinates.js", "./setup/featureCollections": "./src/setup/featureCollections.js", "./setup/features": "./src/setup/features.js", + "./setup/functional": "./src/setup/functional.js", "./setup/geometries": "./src/setup/geometries.js" }, "repository": { @@ -49,6 +50,7 @@ "test:boundingboxes": "jest tests/boundingBoxes --coverage --verbose", "test:featurecollections": "jest tests/featureCollections --coverage --verbose", "test:features": "jest tests/features --coverage --verbose", + "test:functional": "jest tests/functional --coverage --verbose", "test:geometries": "jest tests/geometries --coverage --verbose", "lint": "eslint . --ext .js --fix", "prepare": "husky install", diff --git a/src/core.js b/src/core.js index ddb75bc..407b49a 100644 --- a/src/core.js +++ b/src/core.js @@ -32,5 +32,7 @@ exports.geometries = { } exports.utilities = { - commonGeometryValidation: require('./core/utilities').commonGeometryValidation + commonGeometryValidation: require('./core/utilities/commonGeometryValidation') + .commonGeometryValidation, + validGeoJSON: require('./core/utilities/validGeoJSON').validGeoJSON } diff --git a/src/core/geometries/anyGeometry.js b/src/core/geometries/anyGeometry.js index 3e0eb5a..168e440 100644 --- a/src/core/geometries/anyGeometry.js +++ b/src/core/geometries/anyGeometry.js @@ -4,7 +4,7 @@ const { lineStringGeometry } = require('./lineStringGeometry') const { multiLineStringGeometry } = require('./multiLineStringGeometry') const { polygonGeometry } = require('./polygonGeometry') const { multiPolygonGeometry } = require('./multiPolygonGeometry') -const { commonGeometryValidation } = require('../utilities') +const { commonGeometryValidation } = require('../utilities/commonGeometryValidation') /** * Verifies an object meets validity requirements for one of the six basic GeoJSON geometry types: diff --git a/src/core/geometries/geometryCollection.js b/src/core/geometries/geometryCollection.js index 3ac98c6..cd10bc9 100644 --- a/src/core/geometries/geometryCollection.js +++ b/src/core/geometries/geometryCollection.js @@ -1,5 +1,5 @@ const { anyGeometry } = require('./anyGeometry') -const { commonGeometryValidation } = require('../utilities') +const { commonGeometryValidation } = require('../utilities/commonGeometryValidation') /** * Verifies an object is a valid GeoJSON GeometryCollection. This object requires a diff --git a/src/core/geometries/lineStringGeometry.js b/src/core/geometries/lineStringGeometry.js index be400ad..ffbca2b 100644 --- a/src/core/geometries/lineStringGeometry.js +++ b/src/core/geometries/lineStringGeometry.js @@ -1,5 +1,5 @@ const { validCoordinate } = require('../coordinates/validCoordinate') -const { commonGeometryValidation } = require('../utilities') +const { commonGeometryValidation } = require('../utilities/commonGeometryValidation') /** * Verifies an object is a valid GeoJSON LineString Geometry. This geometry requires a diff --git a/src/core/geometries/multiLineStringGeometry.js b/src/core/geometries/multiLineStringGeometry.js index 7c3a8e5..1d1f259 100644 --- a/src/core/geometries/multiLineStringGeometry.js +++ b/src/core/geometries/multiLineStringGeometry.js @@ -1,5 +1,5 @@ const { validCoordinate } = require('../coordinates/validCoordinate') -const { commonGeometryValidation } = require('../utilities') +const { commonGeometryValidation } = require('../utilities/commonGeometryValidation') /** * Verifies an object is a valid GeoJSON MultiLineString Geometry. This geometry requires a diff --git a/src/core/geometries/multiPointGeometry.js b/src/core/geometries/multiPointGeometry.js index 716e3ef..48f0346 100644 --- a/src/core/geometries/multiPointGeometry.js +++ b/src/core/geometries/multiPointGeometry.js @@ -1,5 +1,5 @@ const { validCoordinate } = require('../coordinates/validCoordinate') -const { commonGeometryValidation } = require('../utilities') +const { commonGeometryValidation } = require('../utilities/commonGeometryValidation') /** * Verifies an object is a valid GeoJSON MultiPoint Geometry. This geometry requires a diff --git a/src/core/geometries/multiPolygonGeometry.js b/src/core/geometries/multiPolygonGeometry.js index c39ed09..cea0af3 100644 --- a/src/core/geometries/multiPolygonGeometry.js +++ b/src/core/geometries/multiPolygonGeometry.js @@ -1,5 +1,5 @@ const { validCoordinate } = require('../coordinates/validCoordinate') -const { commonGeometryValidation } = require('../utilities') +const { commonGeometryValidation } = require('../utilities/commonGeometryValidation') /** * Verifies an object is a valid GeoJSON MultiPolygon Geometry. This geometry requires a diff --git a/src/core/geometries/pointGeometry.js b/src/core/geometries/pointGeometry.js index 01b3979..0b8ad98 100644 --- a/src/core/geometries/pointGeometry.js +++ b/src/core/geometries/pointGeometry.js @@ -1,5 +1,5 @@ const { validCoordinate } = require('../coordinates/validCoordinate') -const { commonGeometryValidation } = require('../utilities') +const { commonGeometryValidation } = require('../utilities/commonGeometryValidation') /** * Verifies an object is a valid GeoJSON Point Geometry. This geometry requires a diff --git a/src/core/geometries/polygonGeometry.js b/src/core/geometries/polygonGeometry.js index fad121f..ba50422 100644 --- a/src/core/geometries/polygonGeometry.js +++ b/src/core/geometries/polygonGeometry.js @@ -1,5 +1,5 @@ const { validCoordinate } = require('../coordinates/validCoordinate') -const { commonGeometryValidation } = require('../utilities') +const { commonGeometryValidation } = require('../utilities/commonGeometryValidation') /** * Verifies an object is a valid GeoJSON Polygon Geometry. This geometry requires a diff --git a/src/core/utilities.js b/src/core/utilities/commonGeometryValidation.js similarity index 97% rename from src/core/utilities.js rename to src/core/utilities/commonGeometryValidation.js index ec22cd6..b8c4e43 100644 --- a/src/core/utilities.js +++ b/src/core/utilities/commonGeometryValidation.js @@ -1,4 +1,4 @@ -const { validBoundingBox } = require('./boundingBoxes/validBoundingBox') +const { validBoundingBox } = require('../boundingBoxes/validBoundingBox') /** * This tests an object to see if it meets common required criteria between all GeoJSON diff --git a/src/core/utilities/validGeoJSON.js b/src/core/utilities/validGeoJSON.js new file mode 100644 index 0000000..cc24975 --- /dev/null +++ b/src/core/utilities/validGeoJSON.js @@ -0,0 +1,128 @@ +const { anyGeometry } = require('../geometries/anyGeometry') +const { feature } = require('../features/feature') +const { featureCollection } = require('../featureCollections/featureCollection') + +/** + * This tests an object to see if it meets validation criteria for any of the seven GeoJSON + * Geometry types, Features, or FeatureCollections. + * + * @memberof Core.Utilities + * @see https://github.com/M-Scott-Lassiter/jest-geojson/issues/26 + * @param {object} geoObject Any GeoJSON Geometry, Feature, or FeatureCollection object + * @returns {boolean} True if a valid GeoJSON object. Will throw a specific error if it encounters a problem. + * @throws {Error} Argument must be a GeoJSON Geometry, Feature, or FeatureCollection object. + * @example + * point = { + * "type": "Point", + * "coordinates": [100.0, 0.0] + * } + * lineString = { + * "type": "LineString", + * "coordinates": [ + * [ + * [180.0, 40.0], + * [180.0, 50.0], + * [170.0, 50.0], + * [170.0, 40.0], + * [180.0, 40.0] + * ] + * ] + * } + * polygon = { + * "type": "Polygon", + * "coordinates": [ + * [ + * [100.0, 0.0], + * [101.0, 0.0], + * [101.0, 1.0], + * [100.0, 1.0], + * [100.0, 0.0] + * ] + * ] + * } + * feature = { + * "type": "Feature", + * "geometry": { + * "type": "Point", + * "coordinates": [102.0, 0.5] + * } + * } + * geometryCollection = { + * "type": "GeometryCollection", + * "geometries": [{ + * "type": "Point", + * "coordinates": [100.0, 0.0] + * }, { + * "type": "LineString", + * "coordinates": [ + * [101.0, 0.0], + * [102.0, 1.0] + * ] + * }, { + * "type": "Polygon", + * "coordinates": [ + * [ + * [102.0, 2.0], + * [103.0, 2.0], + * [103.0, 3.0], + * [102.0, 3.0], + * [102.0, 2.0] + * ] + * ] + * }, { + * "type": "Point", + * "coordinates": [150.0, 73.0] + * }] + * } + * + * // All of these will return true: + * + * validGeoJSON(point) + * validGeoJSON(lineString) + * validGeoJSON(polygon) + * validGeoJSON(feature) + * validGeoJSON(feature.geometry) + * validGeoJSON(geometryCollection) + * validGeoJSON(geometryCollection.geometries[1]) + * @example + * // All of these throw errors: + * + * validGeoJSON(polygon.coordinates) + * validGeoJSON(geometryCollection.geometries) + * validGeoJSON([322, -34.549, 0]) + * validGeoJSON({coordinates: [22, -34.549, 22]}) + */ +function validGeoJSON(geoObject) { + if (typeof geoObject !== 'object' || geoObject === null || Array.isArray(geoObject)) { + throw new Error( + 'Argument must be a GeoJSON Geometry, Feature, or FeatureCollection object.' + ) + } + + if (geoObject.type === 'Feature') { + try { + feature(geoObject) + return true + } catch (err) { + throw new Error(err) + } + } + + if (geoObject.type === 'FeatureCollection') { + try { + featureCollection(geoObject) + return true + } catch (err) { + throw new Error(err) + } + } + + try { + anyGeometry(geoObject) + return true + } catch (err) { + throw new Error(err) + } +} + +exports.validGeoJSON = validGeoJSON diff --git a/src/matchers.js b/src/matchers.js index 3e129d9..a9f3f0f 100644 --- a/src/matchers.js +++ b/src/matchers.js @@ -26,6 +26,10 @@ exports.features = { toBeFeature: require('./matchers/features/toBeFeature').toBeFeature } +exports.functional = { + toBeValidGeoJSON: require('./matchers/functional/toBeValidGeoJSON').toBeValidGeoJSON +} + exports.geometries = { toBeAnyGeometry: require('./matchers/geometries/toBeAnyGeometry').toBeAnyGeometry, toBeGeometryCollection: require('./matchers/geometries/toBeGeometryCollection') diff --git a/src/matchers/functional/toBeValidGeoJSON.js b/src/matchers/functional/toBeValidGeoJSON.js new file mode 100644 index 0000000..83b706d --- /dev/null +++ b/src/matchers/functional/toBeValidGeoJSON.js @@ -0,0 +1,127 @@ +const { validGeoJSON } = require('../../core/utilities/validGeoJSON') + +// eslint-disable-next-line jsdoc/require-returns +/** + * This tests an object to see if it meets validation criteria for any of the seven GeoJSON + * Geometry types, Features, or FeatureCollections. + * + * + * @memberof Matchers.Functional + * @see https://github.com/M-Scott-Lassiter/jest-geojson/issues/26 + * @param {object} geoObject Any GeoJSON Geometry, Feature, or FeatureCollection object + * @example + * point = { + * "type": "Point", + * "coordinates": [100.0, 0.0] + * } + * lineString = { + * "type": "LineString", + * "coordinates": [ + * [ + * [180.0, 40.0], + * [180.0, 50.0], + * [170.0, 50.0], + * [170.0, 40.0], + * [180.0, 40.0] + * ] + * ] + * } + * polygon = { + * "type": "Polygon", + * "coordinates": [ + * [ + * [100.0, 0.0], + * [101.0, 0.0], + * [101.0, 1.0], + * [100.0, 1.0], + * [100.0, 0.0] + * ] + * ] + * } + * feature = { + * "type": "Feature", + * "geometry": { + * "type": "Point", + * "coordinates": [102.0, 0.5] + * } + * } + * geometryCollection = { + * "type": "GeometryCollection", + * "geometries": [{ + * "type": "Point", + * "coordinates": [100.0, 0.0] + * }, { + * "type": "LineString", + * "coordinates": [ + * [101.0, 0.0], + * [102.0, 1.0] + * ] + * }, { + * "type": "Polygon", + * "coordinates": [ + * [ + * [102.0, 2.0], + * [103.0, 2.0], + * [103.0, 3.0], + * [102.0, 3.0], + * [102.0, 2.0] + * ] + * ] + * }, { + * "type": "Point", + * "coordinates": [150.0, 73.0] + * }] + * } + * + * test('Object is valid GeoJSON Feature', () => { + * expect(point).toBeValidGeoJSON() + * expect(lineString).toBeValidGeoJSON() + * expect(polygon).toBeValidGeoJSON() + * expect(feature).toBeValidGeoJSON() + * expect(feature.geometry).toBeValidGeoJSON() + * expect(geometryCollection).toBeValidGeoJSON() + * expect(geometryCollection.geometries[1]).toBeValidGeoJSON() + * }) + * @example + * test('Object is NOT valid GeoJSON Geometry Object', () => { + * expect(polygon.coordinates).not.toBeValidGeoJSON() + * expect(geometryCollection.geometries).toBeValidGeoJSON() + * expect([322, -34.549, 0]).not.toBeValidGeoJSON() + * expect({coordinates: [22, -34.549, 22]}).not.toBeValidGeoJSON() + * }) + */ +function toBeValidGeoJSON(geoObject) { + const { printReceived, matcherHint } = this.utils + const passMessage = + // eslint-disable-next-line prefer-template + matcherHint('.not.toBeValidGeoJSON', 'GeoJSONObject', '') + + '\n\n' + + `Expected input to not be a valid GeoJSON Geometry, Feature, or FeatureCollection object.\n\n` + + `Received: ${printReceived(geoObject)}` + + /** + * Combines a custom error message with built in Jest tools to provide a more descriptive error + * meessage to the end user. + * + * @param {string} errorMessage Error message text to return to the user + * @returns {string} Concatenated Jest test result string + */ + function failMessage(errorMessage) { + return ( + // eslint-disable-next-line prefer-template, no-unused-expressions + matcherHint('.toBeValidGeoJSON', 'GeoJSONObject', '') + + '\n\n' + + `${errorMessage}\n\n` + + `Received: ${printReceived(geoObject)}` + ) + } + + try { + validGeoJSON(geoObject) + } catch (err) { + return { pass: false, message: () => failMessage(err.message) } + } + return { pass: true, message: () => passMessage } +} + +exports.toBeValidGeoJSON = toBeValidGeoJSON diff --git a/src/setup/all.js b/src/setup/all.js index b2e3938..010edac 100644 --- a/src/setup/all.js +++ b/src/setup/all.js @@ -15,6 +15,7 @@ if (jestExpect !== undefined) { expect.extend(matchers.boundingBoxes) expect.extend(matchers.featureCollections) expect.extend(matchers.features) + expect.extend(matchers.functional) expect.extend(matchers.geometries) } else { exports.throwJestRuntimeError() diff --git a/src/setup/functional.js b/src/setup/functional.js new file mode 100644 index 0000000..513846d --- /dev/null +++ b/src/setup/functional.js @@ -0,0 +1,10 @@ +const matchers = require('../matchers') +const { throwJestRuntimeError } = require('./all') + +const jestExpect = global.expect + +if (jestExpect !== undefined) { + expect.extend(matchers.functional) +} else { + throwJestRuntimeError() +} diff --git a/src/typedefinitions.js b/src/typedefinitions.js index b45b8e7..5b1c875 100644 --- a/src/typedefinitions.js +++ b/src/typedefinitions.js @@ -55,6 +55,12 @@ * @namespace Matchers.Features */ +/** + * Functional matchers assess more generic attributes and qualities and many accept multiple input types. + * + * @namespace Matchers.Functional + */ + /** * A set of matchers related to validating the seven geometry objects. * diff --git a/tests/boundingBoxes/isValid2DBoundingBox.test.js b/tests/boundingBoxes/isValid2DBoundingBox.test.js index f792bee..3ee220b 100644 --- a/tests/boundingBoxes/isValid2DBoundingBox.test.js +++ b/tests/boundingBoxes/isValid2DBoundingBox.test.js @@ -59,6 +59,7 @@ describe('Valid Use Cases', () => { test.each([...goodBBoxes])('expect(%p)', (bboxArray) => { expect(bboxArray).isValid2DBoundingBox() expect(bboxArray).isValidBoundingBox() + expect(bboxArray).not.toBeValidGeoJSON() }) }) @@ -66,6 +67,7 @@ describe('Valid Use Cases', () => { test.each([...goodBoundaryCoordinates])('expect(%p)', (bboxArray) => { expect(bboxArray).isValid2DBoundingBox() expect(bboxArray).isValidBoundingBox() + expect(bboxArray).not.toBeValidGeoJSON() }) }) }) diff --git a/tests/boundingBoxes/isValid3DBoundingBox.test.js b/tests/boundingBoxes/isValid3DBoundingBox.test.js index e6ca112..3150a59 100644 --- a/tests/boundingBoxes/isValid3DBoundingBox.test.js +++ b/tests/boundingBoxes/isValid3DBoundingBox.test.js @@ -78,6 +78,7 @@ describe('Valid Use Cases', () => { test.each([...goodBBoxes])('expect(%p)', (bboxArray) => { expect(bboxArray).isValid3DBoundingBox() expect(bboxArray).isValidBoundingBox() + expect(bboxArray).not.toBeValidGeoJSON() }) }) @@ -85,6 +86,7 @@ describe('Valid Use Cases', () => { test.each([...goodBoundaryCoordinates])('expect(%p)', (bboxArray) => { expect(bboxArray).isValid3DBoundingBox() expect(bboxArray).isValidBoundingBox() + expect(bboxArray).not.toBeValidGeoJSON() }) }) }) diff --git a/tests/coordinates/isValid2DCoordinate.test.js b/tests/coordinates/isValid2DCoordinate.test.js index 7f2df42..1f3e435 100644 --- a/tests/coordinates/isValid2DCoordinate.test.js +++ b/tests/coordinates/isValid2DCoordinate.test.js @@ -50,6 +50,7 @@ describe('Valid Use Cases', () => { test.each([...goodCoordinates])('expect(%p)', (coordinate) => { expect(coordinate).isValid2DCoordinate() expect(coordinate).isValidCoordinate() + expect(coordinate).not.toBeValidGeoJSON() }) }) @@ -57,6 +58,7 @@ describe('Valid Use Cases', () => { test.each([...goodBoundaryCoordinates])('expect(%p)', (coordinate) => { expect(coordinate).isValid2DCoordinate() expect(coordinate).isValidCoordinate() + expect(coordinate).not.toBeValidGeoJSON() }) }) }) diff --git a/tests/coordinates/isValid3DCoordinate.test.js b/tests/coordinates/isValid3DCoordinate.test.js index b82beef..17dfde6 100644 --- a/tests/coordinates/isValid3DCoordinate.test.js +++ b/tests/coordinates/isValid3DCoordinate.test.js @@ -63,6 +63,7 @@ describe('Valid Use Cases', () => { test.each([...goodCoordinates])('expect(%p)', (coordinate) => { expect(coordinate).isValid3DCoordinate() expect(coordinate).isValidCoordinate() + expect(coordinate).not.toBeValidGeoJSON() }) }) @@ -70,6 +71,7 @@ describe('Valid Use Cases', () => { test.each([...goodBoundaryCoordinates])('expect([%p])', (coordinate) => { expect(coordinate).isValid3DCoordinate() expect(coordinate).isValidCoordinate() + expect(coordinate).not.toBeValidGeoJSON() }) }) }) diff --git a/tests/core.test.js b/tests/core.test.js index bc8c7bb..1151d87 100644 --- a/tests/core.test.js +++ b/tests/core.test.js @@ -80,4 +80,8 @@ describe('Utility Functions Exported', () => { test('commonGeometryValidation', () => { expect('commonGeometryValidation' in core.utilities).toBeTruthy() }) + + test('validGeoJSON', () => { + expect('validGeoJSON' in core.utilities).toBeTruthy() + }) }) diff --git a/tests/featureCollections/toBeFeatureCollection.test.js b/tests/featureCollections/toBeFeatureCollection.test.js index 58077cd..2a9f4d7 100644 --- a/tests/featureCollections/toBeFeatureCollection.test.js +++ b/tests/featureCollections/toBeFeatureCollection.test.js @@ -108,41 +108,49 @@ describe('Valid Use Cases', () => { test('Known good FeatureCollection', () => { expect(goodFeatureCollection).toBeFeatureCollection() + expect(goodFeatureCollection).toBeValidGeoJSON() }) test('Point', () => { testFeatureCollection.features[0].geometry = goodGeometry.point expect(testFeatureCollection).toBeFeatureCollection() + expect(testFeatureCollection).toBeValidGeoJSON() }) test('MultiPoint', () => { testFeatureCollection.features[0].geometry = goodGeometry.multiPoint expect(testFeatureCollection).toBeFeatureCollection() + expect(testFeatureCollection).toBeValidGeoJSON() }) test('LineString', () => { testFeatureCollection.features[0].geometry = goodGeometry.lineString expect(testFeatureCollection).toBeFeatureCollection() + expect(testFeatureCollection).toBeValidGeoJSON() }) test('MultiLineString', () => { testFeatureCollection.features[0].geometry = goodGeometry.multiLineString expect(testFeatureCollection).toBeFeatureCollection() + expect(testFeatureCollection).toBeValidGeoJSON() }) test('Polygon', () => { testFeatureCollection.features[0].geometry = goodGeometry.polygon expect(testFeatureCollection).toBeFeatureCollection() + expect(testFeatureCollection).toBeValidGeoJSON() }) test('MultiPolygon', () => { testFeatureCollection.features[0].geometry = goodGeometry.multiPolygon expect(testFeatureCollection).toBeFeatureCollection() + expect(testFeatureCollection).toBeValidGeoJSON() }) test('Geometry Collection', () => { testFeatureCollection.features[0].geometry = nestedGeometryCollection expect(testFeatureCollection).toBeFeatureCollection() + expect(testFeatureCollection).toBeValidGeoJSON() }) test('All', () => { @@ -156,6 +164,7 @@ describe('Valid Use Cases', () => { { type: 'Feature', properties: {}, geometry: nestedGeometryCollection } ] expect(testFeatureCollection).toBeFeatureCollection() + expect(testFeatureCollection).toBeValidGeoJSON() }) test('Stress Test', () => { @@ -198,11 +207,13 @@ describe('Valid Use Cases', () => { }) } expect(testFeatureCollection).toBeFeatureCollection() + expect(testFeatureCollection).toBeValidGeoJSON() }) test('Empty Array', () => { testFeatureCollection.features = [] expect(testFeatureCollection).toBeFeatureCollection() + expect(testFeatureCollection).toBeValidGeoJSON() }) }) @@ -227,6 +238,7 @@ describe('Valid Use Cases', () => { } expect(testFeatureCollection).toBeFeatureCollection() + expect(testFeatureCollection).toBeValidGeoJSON() }) }) @@ -238,6 +250,7 @@ describe('Valid Use Cases', () => { foreign: true } expect(testFeatureCollection).toBeFeatureCollection() + expect(testFeatureCollection).toBeValidGeoJSON() }) test('Multiple Foreign Properties', () => { @@ -249,6 +262,7 @@ describe('Valid Use Cases', () => { foreign2: 33 } expect(testFeatureCollection).toBeFeatureCollection() + expect(testFeatureCollection).toBeValidGeoJSON() }) test('Foreign Property That Would Normally be a Valid GeoJSON Object', () => { @@ -266,6 +280,7 @@ describe('Valid Use Cases', () => { Geometry: multiPoint // Note captitalized 'G' } expect(testFeatureCollection).toBeFeatureCollection() + expect(testFeatureCollection).toBeValidGeoJSON() }) }) @@ -289,6 +304,7 @@ describe('Valid Use Cases', () => { } expect(testFeatureCollection).toBeFeatureCollection() + expect(testFeatureCollection).toBeValidGeoJSON() }) test('3D Bounding Box', () => { @@ -300,6 +316,7 @@ describe('Valid Use Cases', () => { } expect(testFeatureCollection).toBeFeatureCollection() + expect(testFeatureCollection).toBeValidGeoJSON() }) test('Illogical Bounding Box', () => { @@ -311,6 +328,7 @@ describe('Valid Use Cases', () => { } expect(testFeatureCollection).toBeFeatureCollection() + expect(testFeatureCollection).toBeValidGeoJSON() }) test('Redundant Bounding Box', () => { @@ -324,6 +342,7 @@ describe('Valid Use Cases', () => { } expect(testFeatureCollection).toBeFeatureCollection() + expect(testFeatureCollection).toBeValidGeoJSON() }) }) }) @@ -334,6 +353,7 @@ describe('Invalid Use Cases', () => { 'expect(%p).not.toBeFeatureCollection()', (badInput) => { expect(badInput).not.toBeFeatureCollection() + expect(badInput).not.toBeValidGeoJSON() } ) }) @@ -350,26 +370,31 @@ describe('Invalid Use Cases', () => { test.each(invalidInputValues)('Invalid Features: %p', (input) => { testFeatureCollection.features = input expect(testFeatureCollection).not.toBeFeatureCollection() + expect(testFeatureCollection).not.toBeValidGeoJSON() }) test.each(invalidInputValues)('Invalid Features: [%p]', (input) => { testFeatureCollection.features = [input] expect(testFeatureCollection).not.toBeFeatureCollection() + expect(testFeatureCollection).not.toBeValidGeoJSON() }) test('Point', () => { testFeatureCollection.features[0].geometry = badGeometry.point expect(testFeatureCollection).not.toBeFeatureCollection() + expect(testFeatureCollection).not.toBeValidGeoJSON() }) test('MultiPoint', () => { testFeatureCollection.features[0].geometry = badGeometry.multiPoint expect(testFeatureCollection).not.toBeFeatureCollection() + expect(testFeatureCollection).not.toBeValidGeoJSON() }) test('LineString', () => { testFeatureCollection.features[0].geometry = badGeometry.lineString expect(testFeatureCollection).not.toBeFeatureCollection() + expect(testFeatureCollection).not.toBeValidGeoJSON() }) test('MultiLineString', () => { @@ -380,16 +405,19 @@ describe('Invalid Use Cases', () => { test('Polygon', () => { testFeatureCollection.features[0].geometry = badGeometry.polygon expect(testFeatureCollection).not.toBeFeatureCollection() + expect(testFeatureCollection).not.toBeValidGeoJSON() }) test('MultiPolygon', () => { testFeatureCollection.features[0].geometry = badGeometry.multiPolygon expect(testFeatureCollection).not.toBeFeatureCollection() + expect(testFeatureCollection).not.toBeValidGeoJSON() }) test('Unrecognized', () => { testFeatureCollection.features[0].geometry = badGeometry.unrecognized expect(testFeatureCollection).not.toBeFeatureCollection() + expect(testFeatureCollection).not.toBeValidGeoJSON() }) test('All', () => { @@ -404,6 +432,7 @@ describe('Invalid Use Cases', () => { { type: 'Feature', properties: {}, geometry: badGeometry.point } ] expect(testFeatureCollection).not.toBeFeatureCollection() + expect(testFeatureCollection).not.toBeValidGeoJSON() }) }) @@ -414,6 +443,7 @@ describe('Invalid Use Cases', () => { features: [] } expect(testFeatureCollection).not.toBeFeatureCollection() + expect(testFeatureCollection).not.toBeValidGeoJSON() }) }) @@ -442,6 +472,7 @@ describe('Invalid Use Cases', () => { bbox: input } expect(testFeatureCollection).not.toBeFeatureCollection() + expect(testFeatureCollection).not.toBeValidGeoJSON() }) }) @@ -467,6 +498,7 @@ describe('Invalid Use Cases', () => { ] } expect(testFeatureCollection).not.toBeFeatureCollection() + expect(testFeatureCollection).not.toBeValidGeoJSON() }) test(`Contains: 'geometries'`, () => { @@ -497,6 +529,7 @@ describe('Invalid Use Cases', () => { } expect(testFeatureCollection).not.toBeFeatureCollection() + expect(testFeatureCollection).not.toBeValidGeoJSON() }) test(`Contains: 'geometry'`, () => { @@ -522,6 +555,7 @@ describe('Invalid Use Cases', () => { } expect(testFeatureCollection).not.toBeFeatureCollection() + expect(testFeatureCollection).not.toBeValidGeoJSON() }) test(`Contains: 'properties'`, () => { @@ -545,6 +579,7 @@ describe('Invalid Use Cases', () => { } expect(testFeatureCollection).not.toBeFeatureCollection() + expect(testFeatureCollection).not.toBeValidGeoJSON() }) }) @@ -554,6 +589,7 @@ describe('Invalid Use Cases', () => { features: [] } expect(testFeatureCollection).not.toBeFeatureCollection() + expect(testFeatureCollection).not.toBeValidGeoJSON() }) test(`Missing: 'geometry'`, () => { @@ -561,6 +597,7 @@ describe('Invalid Use Cases', () => { type: 'FeatureCollection' } expect(testFeatureCollection).not.toBeFeatureCollection() + expect(testFeatureCollection).not.toBeValidGeoJSON() }) }) }) diff --git a/tests/features/toBeFeature.test.js b/tests/features/toBeFeature.test.js index 190911b..c0f5b16 100644 --- a/tests/features/toBeFeature.test.js +++ b/tests/features/toBeFeature.test.js @@ -59,6 +59,7 @@ describe('Valid Use Cases', () => { expect(testFeature).toBeFeature() expect(testFeature).toBeFeature('Point') expect(testFeature).not.toBeFeature('MultiPoint') + expect(testFeature).toBeValidGeoJSON() }) test('MultiPoint', () => { @@ -66,6 +67,7 @@ describe('Valid Use Cases', () => { expect(testFeature).toBeFeature() expect(testFeature).toBeFeature('MultiPoint') expect(testFeature).not.toBeFeature('Point') + expect(testFeature).toBeValidGeoJSON() }) test('LineString', () => { @@ -73,6 +75,7 @@ describe('Valid Use Cases', () => { expect(testFeature).toBeFeature() expect(testFeature).toBeFeature('LineString') expect(testFeature).not.toBeFeature('MultiLineString') + expect(testFeature).toBeValidGeoJSON() }) test('MultiLineString', () => { @@ -80,6 +83,7 @@ describe('Valid Use Cases', () => { expect(testFeature).toBeFeature() expect(testFeature).toBeFeature('MultiLineString') expect(testFeature).not.toBeFeature('LineString') + expect(testFeature).toBeValidGeoJSON() }) test('Polygon', () => { @@ -87,6 +91,7 @@ describe('Valid Use Cases', () => { expect(testFeature).toBeFeature() expect(testFeature).toBeFeature('Polygon') expect(testFeature).not.toBeFeature('MultiPolygon') + expect(testFeature).toBeValidGeoJSON() }) test('MultiPolygon', () => { @@ -94,6 +99,7 @@ describe('Valid Use Cases', () => { expect(testFeature).toBeFeature() expect(testFeature).toBeFeature('MultiPolygon') expect(testFeature).not.toBeFeature('Polygon') + expect(testFeature).toBeValidGeoJSON() }) test('Nested GeometryCollections', () => { @@ -101,6 +107,7 @@ describe('Valid Use Cases', () => { expect(testFeature).toBeFeature() expect(testFeature).toBeFeature('GeometryCollection') expect(testFeature).not.toBeFeature('Polygon') + expect(testFeature).toBeValidGeoJSON() }) test('Geometry May be a Null Value', () => { @@ -108,6 +115,7 @@ describe('Valid Use Cases', () => { testFeature.properties.prop2 = true expect(testFeature).toBeFeature() expect(testFeature).not.toBeFeature('Polygon') + expect(testFeature).toBeValidGeoJSON() }) }) @@ -120,6 +128,7 @@ describe('Valid Use Cases', () => { } expect(testFeature).toBeFeature() expect(testFeature).not.toBeFeature('MultiPoint') + expect(testFeature).toBeValidGeoJSON() }) test('properties: {}', () => { @@ -130,6 +139,7 @@ describe('Valid Use Cases', () => { } expect(testFeature).toBeFeature() expect(testFeature).not.toBeFeature('Point') + expect(testFeature).toBeValidGeoJSON() }) }) @@ -154,6 +164,7 @@ describe('Valid Use Cases', () => { properties: null } expect(testFeature).toBeFeature() + expect(testFeature).toBeValidGeoJSON() }) }) @@ -166,6 +177,7 @@ describe('Valid Use Cases', () => { foreign: true } expect(testFeature).toBeFeature() + expect(testFeature).toBeValidGeoJSON() }) test('Multiple Foreign Properties', () => { @@ -178,6 +190,7 @@ describe('Valid Use Cases', () => { foreign2: 33 } expect(testFeature).toBeFeature() + expect(testFeature).toBeValidGeoJSON() }) test('Foreign Property That Would Normally be a Valid GeoJSON Object', () => { @@ -197,6 +210,7 @@ describe('Valid Use Cases', () => { } expect(testFeature).toBeFeature() + expect(testFeature).toBeValidGeoJSON() }) }) @@ -220,6 +234,7 @@ describe('Valid Use Cases', () => { } expect(testFeature).toBeFeature() + expect(testFeature).toBeValidGeoJSON() }) test('3D Bounding Box', () => { @@ -241,6 +256,7 @@ describe('Valid Use Cases', () => { } expect(testFeature).toBeFeature() + expect(testFeature).toBeValidGeoJSON() }) test('Illogical Bounding Box', () => { @@ -262,6 +278,7 @@ describe('Valid Use Cases', () => { } expect(testFeature).toBeFeature() + expect(testFeature).toBeValidGeoJSON() }) test('Redundant Bounding Box', () => { @@ -273,6 +290,7 @@ describe('Valid Use Cases', () => { } expect(testFeature).toBeFeature() + expect(testFeature).toBeValidGeoJSON() }) }) }) @@ -281,6 +299,7 @@ describe('Invalid Use Cases', () => { describe('Expect to fail with bad inputs:', () => { test.each([...invalidInputValues, null])('expect(%p).not.toBeFeature()', (badInput) => { expect(badInput).not.toBeFeature() + expect(badInput).not.toBeValidGeoJSON() }) }) @@ -297,42 +316,49 @@ describe('Invalid Use Cases', () => { testFeature.geometry = badGeometry.point expect(testFeature).not.toBeFeature() expect(testFeature).not.toBeFeature('MultiPoint') + expect(testFeature).not.toBeValidGeoJSON() }) test('MultiPoint', () => { testFeature.geometry = badGeometry.multiPoint expect(testFeature).not.toBeFeature() expect(testFeature).not.toBeFeature('Point') + expect(testFeature).not.toBeValidGeoJSON() }) test('LineString', () => { testFeature.geometry = badGeometry.lineString expect(testFeature).not.toBeFeature() expect(testFeature).not.toBeFeature('MultiLineString') + expect(testFeature).not.toBeValidGeoJSON() }) test('MultiLineString', () => { testFeature.geometry = badGeometry.multiLineString expect(testFeature).not.toBeFeature() expect(testFeature).not.toBeFeature('LineString') + expect(testFeature).not.toBeValidGeoJSON() }) test('Polygon', () => { testFeature.geometry = badGeometry.polygon expect(testFeature).not.toBeFeature() expect(testFeature).not.toBeFeature('MultiPolygon') + expect(testFeature).not.toBeValidGeoJSON() }) test('MultiPolygon', () => { testFeature.geometry = badGeometry.multiPolygon expect(testFeature).not.toBeFeature() expect(testFeature).not.toBeFeature('Polygon') + expect(testFeature).not.toBeValidGeoJSON() }) test('Unrecognized', () => { testFeature.geometry = badGeometry.unrecognized expect(testFeature).not.toBeFeature() expect(testFeature).not.toBeFeature('Polygon') + expect(testFeature).not.toBeValidGeoJSON() }) test('All', () => { @@ -346,6 +372,7 @@ describe('Invalid Use Cases', () => { ] expect(testFeature).not.toBeFeature() expect(testFeature).not.toBeFeature('Polygon') + expect(testFeature).not.toBeValidGeoJSON() }) }) @@ -357,6 +384,7 @@ describe('Invalid Use Cases', () => { properties: null } expect(testFeature).not.toBeFeature() + expect(testFeature).not.toBeValidGeoJSON() }) }) @@ -381,6 +409,7 @@ describe('Invalid Use Cases', () => { bbox: input } expect(testFeature).not.toBeFeature() + expect(testFeature).not.toBeValidGeoJSON() }) }) @@ -407,6 +436,7 @@ describe('Invalid Use Cases', () => { id: input } expect(testFeature).not.toBeFeature() + expect(testFeature).not.toBeValidGeoJSON() }) }) @@ -425,6 +455,7 @@ describe('Invalid Use Cases', () => { properties: null } expect(testFeature).not.toBeFeature() + expect(testFeature).not.toBeValidGeoJSON() }) test(`Contains: 'geometries'`, () => { @@ -448,6 +479,7 @@ describe('Invalid Use Cases', () => { } expect(testFeature).not.toBeFeature() + expect(testFeature).not.toBeValidGeoJSON() }) test(`Contains: 'features'`, () => { @@ -474,6 +506,7 @@ describe('Invalid Use Cases', () => { } expect(testFeature).not.toBeFeature() + expect(testFeature).not.toBeValidGeoJSON() }) describe('Expect to fail when missing required properties:', () => { @@ -486,6 +519,7 @@ describe('Invalid Use Cases', () => { } } expect(testFeature).not.toBeFeature() + expect(testFeature).not.toBeValidGeoJSON() }) test(`Missing: 'geometry'`, () => { @@ -494,6 +528,7 @@ describe('Invalid Use Cases', () => { properties: null } expect(testFeature).not.toBeFeature() + expect(testFeature).not.toBeValidGeoJSON() }) test(`Missing: 'properties'`, () => { @@ -502,6 +537,7 @@ describe('Invalid Use Cases', () => { geometry: null } expect(testFeature).not.toBeFeature() + expect(testFeature).not.toBeValidGeoJSON() }) }) @@ -514,6 +550,7 @@ describe('Invalid Use Cases', () => { } expect(testFeature).not.toBeFeature() + expect(testFeature).not.toBeValidGeoJSON() }) test(`Single Element Array`, () => { @@ -529,6 +566,7 @@ describe('Invalid Use Cases', () => { } expect(testFeature).not.toBeFeature() + expect(testFeature).not.toBeValidGeoJSON() }) test(`Multiple Elements Array`, () => { @@ -547,6 +585,7 @@ describe('Invalid Use Cases', () => { ] } expect(testFeature).not.toBeFeature() + expect(testFeature).not.toBeValidGeoJSON() }) }) @@ -559,6 +598,7 @@ describe('Invalid Use Cases', () => { } expect(testFeature).not.toBeFeature() + expect(testFeature).not.toBeValidGeoJSON() }) }) }) diff --git a/tests/functional/__snapshots__/toBeValidGeoJSON.test.js.snap b/tests/functional/__snapshots__/toBeValidGeoJSON.test.js.snap new file mode 100644 index 0000000..efbc948 --- /dev/null +++ b/tests/functional/__snapshots__/toBeValidGeoJSON.test.js.snap @@ -0,0 +1,17 @@ +// Jest Snapshot v1, https://goo.gl/fbAQLP + +exports[`Error Snapshot Testing. Throws error: Invalid input to matcher 1`] = ` +"expect(GeoJSONObject).toBeValidGeoJSON() + +Argument must be a GeoJSON Geometry, Feature, or FeatureCollection object. + +Received: false" +`; + +exports[`Error Snapshot Testing. Throws error: Valid use case passes 1`] = ` +"expect(GeoJSONObject).not.toBeValidGeoJSON() + +Expected input to not be a valid GeoJSON Geometry, Feature, or FeatureCollection object. + +Received: {\\"coordinates\\": [0, 0], \\"type\\": \\"Point\\"}" +`; diff --git a/tests/functional/toBeValidGeoJSON.test.js b/tests/functional/toBeValidGeoJSON.test.js new file mode 100644 index 0000000..2aa412f --- /dev/null +++ b/tests/functional/toBeValidGeoJSON.test.js @@ -0,0 +1,74 @@ +const invalidInputValues = [ + undefined, + null, + true, + false, + 200, + -200, + Infinity, + -Infinity, + NaN, + [[25, 35, 45000]], + [ + [ + [0, 0], + [1, 1] + ] + ], + [[]], + '', + 'Random Geometry', + JSON.stringify({ + type: 'LineString', + coordinates: [ + [25, 90], + [2, 2] + ] + }), + [[-10, -10, 10, 10]], + + [[-10, -10, 0, 10, 10, 0]], + [ + [ + { + type: 'Point', + coordinates: [100.0, 0.0] + }, + { + type: 'LineString', + coordinates: [ + [ + [180.0, 40.0], + [180.0, 50.0], + [170.0, 50.0], + [170.0, 40.0], + [180.0, 40.0] + ] + ] + } + ] + ], + {} +] + +// All valid use cases contained within the Geometry, Feature, and FeatureCollection tests. + +describe('Invalid Use Cases', () => { + describe('Expect to fail with bad inputs:', () => { + test.each(invalidInputValues)('expect(%p).not.toBeValidGeoJSON()', (badInput) => { + expect(badInput).not.toBeValidGeoJSON() + }) + }) +}) + +describe('Error Snapshot Testing. Throws error:', () => { + test(`Valid use case passes`, () => { + expect(() => + expect({ type: 'Point', coordinates: [0, 0] }).not.toBeValidGeoJSON() + ).toThrowErrorMatchingSnapshot() + }) + + test('Invalid input to matcher', () => { + expect(() => expect(false).toBeValidGeoJSON()).toThrowErrorMatchingSnapshot() + }) +}) diff --git a/tests/geometries/toBeAnyGeometry.test.js b/tests/geometries/toBeAnyGeometry.test.js index 649dd5c..63cd38d 100644 --- a/tests/geometries/toBeAnyGeometry.test.js +++ b/tests/geometries/toBeAnyGeometry.test.js @@ -63,27 +63,7 @@ const featureCollection = { ] } -describe('Valid Use Cases', () => { - test('Expect to pass with GeometryCollection', () => { - const geometryCollection = { - type: 'GeometryCollection', - geometries: [ - { - type: 'Point', - coordinates: [100.0, 0.0] - }, - { - type: 'LineString', - coordinates: [ - [101.0, 0.0], - [102.0, 1.0] - ] - } - ] - } - expect(geometryCollection).toBeAnyGeometry() - }) -}) +// All valid use cases contained within the other Geometry tests. describe('Invalid Use Cases', () => { test('Expect to fail with Feature', () => { diff --git a/tests/geometries/toBeGeometryCollection.test.js b/tests/geometries/toBeGeometryCollection.test.js index 1672a58..269f966 100644 --- a/tests/geometries/toBeGeometryCollection.test.js +++ b/tests/geometries/toBeGeometryCollection.test.js @@ -86,6 +86,7 @@ describe('Valid Use Cases', () => { test('Known Good Collection', () => { expect(goodGeometryCollection).toBeGeometryCollection() expect(goodGeometryCollection).toBeAnyGeometry() + expect(goodGeometryCollection).toBeValidGeoJSON() }) test('Point', () => { @@ -95,6 +96,7 @@ describe('Valid Use Cases', () => { } expect(testGeometryCollection).toBeGeometryCollection() expect(testGeometryCollection).toBeAnyGeometry() + expect(goodGeometryCollection).toBeValidGeoJSON() }) test('MultiPoint', () => { @@ -104,6 +106,7 @@ describe('Valid Use Cases', () => { } expect(testGeometryCollection).toBeGeometryCollection() expect(testGeometryCollection).toBeAnyGeometry() + expect(goodGeometryCollection).toBeValidGeoJSON() }) test('LineString', () => { @@ -113,6 +116,7 @@ describe('Valid Use Cases', () => { } expect(testGeometryCollection).toBeGeometryCollection() expect(testGeometryCollection).toBeAnyGeometry() + expect(goodGeometryCollection).toBeValidGeoJSON() }) test('MultiLineString', () => { @@ -122,6 +126,7 @@ describe('Valid Use Cases', () => { } expect(testGeometryCollection).toBeGeometryCollection() expect(testGeometryCollection).toBeAnyGeometry() + expect(goodGeometryCollection).toBeValidGeoJSON() }) test('Polygon', () => { @@ -131,6 +136,7 @@ describe('Valid Use Cases', () => { } expect(testGeometryCollection).toBeGeometryCollection() expect(testGeometryCollection).toBeAnyGeometry() + expect(goodGeometryCollection).toBeValidGeoJSON() }) test('MultiPolygon', () => { @@ -140,6 +146,7 @@ describe('Valid Use Cases', () => { } expect(testGeometryCollection).toBeGeometryCollection() expect(testGeometryCollection).toBeAnyGeometry() + expect(goodGeometryCollection).toBeValidGeoJSON() }) test('All', () => { @@ -156,11 +163,13 @@ describe('Valid Use Cases', () => { } expect(testGeometryCollection).toBeGeometryCollection() expect(testGeometryCollection).toBeAnyGeometry() + expect(goodGeometryCollection).toBeValidGeoJSON() }) test('Nested GeometryCollections', () => { expect(nestedGeometryCollection).toBeGeometryCollection() expect(goodGeometryCollection).toBeAnyGeometry() + expect(goodGeometryCollection).toBeValidGeoJSON() }) test('Stress Test', () => { @@ -181,6 +190,7 @@ describe('Valid Use Cases', () => { } expect(testGeometryCollection).toBeGeometryCollection() expect(testGeometryCollection).toBeAnyGeometry() + expect(goodGeometryCollection).toBeValidGeoJSON() }) }) @@ -193,6 +203,7 @@ describe('Valid Use Cases', () => { } expect(testGeometryCollection).toBeGeometryCollection() expect(testGeometryCollection).toBeAnyGeometry() + expect(goodGeometryCollection).toBeValidGeoJSON() }) test('Multiple Foreign Properties', () => { @@ -209,6 +220,7 @@ describe('Valid Use Cases', () => { } expect(testGeometryCollection).toBeGeometryCollection() expect(testGeometryCollection).toBeAnyGeometry() + expect(goodGeometryCollection).toBeValidGeoJSON() }) }) @@ -219,6 +231,7 @@ describe('Valid Use Cases', () => { } expect(testGeometryCollection).toBeGeometryCollection() expect(testGeometryCollection).toBeAnyGeometry() + expect(goodGeometryCollection).toBeValidGeoJSON() }) describe('Bounding Boxes Allowed, Must be Valid:', () => { @@ -235,6 +248,7 @@ describe('Valid Use Cases', () => { } expect(testGeometryCollection).toBeGeometryCollection() expect(testGeometryCollection).toBeAnyGeometry() + expect(goodGeometryCollection).toBeValidGeoJSON() }) test('3D Bounding Box', () => { @@ -250,6 +264,7 @@ describe('Valid Use Cases', () => { } expect(testGeometryCollection).toBeGeometryCollection() expect(testGeometryCollection).toBeAnyGeometry() + expect(goodGeometryCollection).toBeValidGeoJSON() }) test('Illogical Bounding Box', () => { @@ -265,6 +280,7 @@ describe('Valid Use Cases', () => { } expect(testGeometryCollection).toBeGeometryCollection() expect(testGeometryCollection).toBeAnyGeometry() + expect(goodGeometryCollection).toBeValidGeoJSON() }) test('Redundant Bounding Box', () => { @@ -280,6 +296,7 @@ describe('Valid Use Cases', () => { } expect(testGeometryCollection).toBeGeometryCollection() expect(testGeometryCollection).toBeAnyGeometry() + expect(goodGeometryCollection).toBeValidGeoJSON() }) }) @@ -297,6 +314,7 @@ describe('Valid Use Cases', () => { } expect(testGeometryCollection).toBeGeometryCollection() expect(testGeometryCollection).toBeAnyGeometry() + expect(goodGeometryCollection).toBeValidGeoJSON() }) }) }) @@ -308,6 +326,7 @@ describe('Invalid Use Cases', () => { (badInput) => { expect(badInput).not.toBeGeometryCollection() expect(badInput).not.toBeAnyGeometry() + expect(badInput).not.toBeValidGeoJSON() } ) }) @@ -320,6 +339,7 @@ describe('Invalid Use Cases', () => { } expect(testGeometryCollection).not.toBeGeometryCollection() expect(testGeometryCollection).not.toBeAnyGeometry() + expect(testGeometryCollection).not.toBeValidGeoJSON() }) test('MultiPoint', () => { @@ -329,6 +349,7 @@ describe('Invalid Use Cases', () => { } expect(testGeometryCollection).not.toBeGeometryCollection() expect(testGeometryCollection).not.toBeAnyGeometry() + expect(testGeometryCollection).not.toBeValidGeoJSON() }) test('LineString', () => { @@ -338,6 +359,7 @@ describe('Invalid Use Cases', () => { } expect(testGeometryCollection).not.toBeGeometryCollection() expect(testGeometryCollection).not.toBeAnyGeometry() + expect(testGeometryCollection).not.toBeValidGeoJSON() }) test('MultiLineString', () => { @@ -347,6 +369,7 @@ describe('Invalid Use Cases', () => { } expect(testGeometryCollection).not.toBeGeometryCollection() expect(testGeometryCollection).not.toBeAnyGeometry() + expect(testGeometryCollection).not.toBeValidGeoJSON() }) test('Polygon', () => { @@ -356,6 +379,7 @@ describe('Invalid Use Cases', () => { } expect(testGeometryCollection).not.toBeGeometryCollection() expect(testGeometryCollection).not.toBeAnyGeometry() + expect(testGeometryCollection).not.toBeValidGeoJSON() }) test('MultiPolygon', () => { @@ -365,6 +389,7 @@ describe('Invalid Use Cases', () => { } expect(testGeometryCollection).not.toBeGeometryCollection() expect(testGeometryCollection).not.toBeAnyGeometry() + expect(testGeometryCollection).not.toBeValidGeoJSON() }) test('Unrecognized', () => { @@ -374,6 +399,7 @@ describe('Invalid Use Cases', () => { } expect(testGeometryCollection).not.toBeGeometryCollection() expect(testGeometryCollection).not.toBeAnyGeometry() + expect(testGeometryCollection).not.toBeValidGeoJSON() }) test('All Bad', () => { @@ -390,6 +416,7 @@ describe('Invalid Use Cases', () => { } expect(testGeometryCollection).not.toBeGeometryCollection() expect(testGeometryCollection).not.toBeAnyGeometry() + expect(testGeometryCollection).not.toBeValidGeoJSON() }) test('All Good With One Bad', () => { @@ -407,6 +434,7 @@ describe('Invalid Use Cases', () => { } expect(testGeometryCollection).not.toBeGeometryCollection() expect(testGeometryCollection).not.toBeAnyGeometry() + expect(testGeometryCollection).not.toBeValidGeoJSON() }) }) @@ -418,6 +446,7 @@ describe('Invalid Use Cases', () => { } expect(testGeometryCollection).not.toBeGeometryCollection() expect(testGeometryCollection).not.toBeAnyGeometry() + expect(testGeometryCollection).not.toBeValidGeoJSON() }) }) @@ -429,6 +458,7 @@ describe('Invalid Use Cases', () => { } expect(testGeometryCollection).not.toBeGeometryCollection() expect(testGeometryCollection).not.toBeAnyGeometry() + expect(testGeometryCollection).not.toBeValidGeoJSON() }) }) @@ -449,6 +479,7 @@ describe('Invalid Use Cases', () => { } expect(testGeometryCollection).not.toBeGeometryCollection() expect(testGeometryCollection).not.toBeAnyGeometry() + expect(testGeometryCollection).not.toBeValidGeoJSON() }) test(`Contains: 'properties'`, () => { @@ -466,6 +497,7 @@ describe('Invalid Use Cases', () => { } expect(testGeometryCollection).not.toBeGeometryCollection() expect(testGeometryCollection).not.toBeAnyGeometry() + expect(testGeometryCollection).not.toBeValidGeoJSON() }) test(`Contains: 'features'`, () => { @@ -492,6 +524,7 @@ describe('Invalid Use Cases', () => { } expect(testGeometryCollection).not.toBeGeometryCollection() expect(testGeometryCollection).not.toBeAnyGeometry() + expect(testGeometryCollection).not.toBeValidGeoJSON() }) }) @@ -502,6 +535,7 @@ describe('Invalid Use Cases', () => { } expect(testGeometryCollection).not.toBeGeometryCollection() expect(testGeometryCollection).not.toBeAnyGeometry() + expect(testGeometryCollection).not.toBeValidGeoJSON() }) test(`Missing: 'geometries'`, () => { @@ -510,6 +544,7 @@ describe('Invalid Use Cases', () => { } expect(testGeometryCollection).not.toBeGeometryCollection() expect(testGeometryCollection).not.toBeAnyGeometry() + expect(testGeometryCollection).not.toBeValidGeoJSON() }) }) @@ -536,6 +571,7 @@ describe('Invalid Use Cases', () => { } expect(testGeometryCollection).not.toBeGeometryCollection() expect(testGeometryCollection).not.toBeAnyGeometry() + expect(testGeometryCollection).not.toBeValidGeoJSON() }) }) }) diff --git a/tests/geometries/toBeLineStringGeometry.test.js b/tests/geometries/toBeLineStringGeometry.test.js index 8519b7b..d6a2bd4 100644 --- a/tests/geometries/toBeLineStringGeometry.test.js +++ b/tests/geometries/toBeLineStringGeometry.test.js @@ -148,6 +148,7 @@ describe('Valid Use Cases', () => { } expect(testLineString).toBeLineStringGeometry() expect(testLineString).toBeAnyGeometry() + expect(testLineString).toBeValidGeoJSON() }) test('Empty coordinate', () => { @@ -157,6 +158,7 @@ describe('Valid Use Cases', () => { } expect(testLineString).toBeLineStringGeometry() expect(testLineString).toBeAnyGeometry() + expect(testLineString).toBeValidGeoJSON() }) test('Stress test with many points', () => { @@ -169,6 +171,7 @@ describe('Valid Use Cases', () => { } expect(testLineString).toBeLineStringGeometry() expect(testLineString).toBeAnyGeometry() + expect(testLineString).toBeValidGeoJSON() }) }) @@ -210,6 +213,7 @@ describe('Valid Use Cases', () => { } expect(testLineString).toBeLineStringGeometry() expect(testLineString).toBeAnyGeometry() + expect(testLineString).toBeValidGeoJSON() }) test.each([testLineString1, testLineString2, testLineString3])( @@ -217,6 +221,7 @@ describe('Valid Use Cases', () => { (testLineString) => { expect(testLineString).toBeLineStringGeometry() expect(testLineString).toBeAnyGeometry() + expect(testLineString).toBeValidGeoJSON() } ) }) @@ -233,6 +238,7 @@ describe('Valid Use Cases', () => { } expect(testLineString).toBeLineStringGeometry() expect(testLineString).toBeAnyGeometry() + expect(testLineString).toBeValidGeoJSON() }) test('3D Bounding Box', () => { @@ -246,6 +252,7 @@ describe('Valid Use Cases', () => { } expect(testLineString).toBeLineStringGeometry() expect(testLineString).toBeAnyGeometry() + expect(testLineString).toBeValidGeoJSON() }) test('Illogical Bounding Box', () => { @@ -259,6 +266,7 @@ describe('Valid Use Cases', () => { } expect(testLineString).toBeLineStringGeometry() expect(testLineString).toBeAnyGeometry() + expect(testLineString).toBeValidGeoJSON() }) test('Redundant Bounding Box', () => { @@ -272,6 +280,7 @@ describe('Valid Use Cases', () => { } expect(testLineString).toBeLineStringGeometry() expect(testLineString).toBeAnyGeometry() + expect(testLineString).toBeValidGeoJSON() }) }) }) @@ -283,6 +292,7 @@ describe('Inalid Use Cases', () => { (badInput) => { expect(badInput).not.toBeLineStringGeometry() expect(badInput).not.toBeAnyGeometry() + expect(badInput).not.toBeValidGeoJSON() } ) }) @@ -297,6 +307,7 @@ describe('Inalid Use Cases', () => { } expect(testLineString).not.toBeLineStringGeometry() expect(testLineString).not.toBeAnyGeometry() + expect(testLineString).not.toBeValidGeoJSON() } ) }) @@ -310,6 +321,7 @@ describe('Inalid Use Cases', () => { } expect(testLineString).not.toBeLineStringGeometry() expect(testLineString).not.toBeAnyGeometry() + expect(testLineString).not.toBeValidGeoJSON() }) }) @@ -321,6 +333,7 @@ describe('Inalid Use Cases', () => { } expect(testLineString).not.toBeLineStringGeometry() expect(testLineString).not.toBeAnyGeometry() + expect(testLineString).not.toBeValidGeoJSON() }) }) @@ -332,6 +345,7 @@ describe('Inalid Use Cases', () => { } expect(testLineString).not.toBeLineStringGeometry() expect(testLineString).not.toBeAnyGeometry() + expect(testLineString).not.toBeValidGeoJSON() }) }) @@ -365,6 +379,7 @@ describe('Inalid Use Cases', () => { expect(testLineString).not.toBeLineStringGeometry() expect(testLineString).not.toBeAnyGeometry() + expect(testLineString).not.toBeValidGeoJSON() }) test(`Contains: 'properties'`, () => { @@ -381,6 +396,7 @@ describe('Inalid Use Cases', () => { expect(testLineString).not.toBeLineStringGeometry() expect(testLineString).not.toBeAnyGeometry() + expect(testLineString).not.toBeValidGeoJSON() }) test(`Contains: 'features'`, () => { @@ -405,6 +421,7 @@ describe('Inalid Use Cases', () => { } expect(testLineString).not.toBeLineStringGeometry() expect(testLineString).not.toBeAnyGeometry() + expect(testLineString).not.toBeValidGeoJSON() }) }) @@ -418,6 +435,7 @@ describe('Inalid Use Cases', () => { } expect(testLineString).not.toBeLineStringGeometry() expect(testLineString).not.toBeAnyGeometry() + expect(testLineString).not.toBeValidGeoJSON() }) test(`Missing: 'coordinates'`, () => { const testLineString = { @@ -425,6 +443,7 @@ describe('Inalid Use Cases', () => { } expect(testLineString).not.toBeLineStringGeometry() expect(testLineString).not.toBeAnyGeometry() + expect(testLineString).not.toBeValidGeoJSON() }) }) @@ -449,6 +468,7 @@ describe('Inalid Use Cases', () => { } expect(testLineString).not.toBeLineStringGeometry() expect(testLineString).not.toBeAnyGeometry() + expect(testLineString).not.toBeValidGeoJSON() }) }) }) diff --git a/tests/geometries/toBeMultiLineStringGeometry.test.js b/tests/geometries/toBeMultiLineStringGeometry.test.js index 24e9967..ccb28a7 100644 --- a/tests/geometries/toBeMultiLineStringGeometry.test.js +++ b/tests/geometries/toBeMultiLineStringGeometry.test.js @@ -136,6 +136,7 @@ describe('Valid Use Cases', () => { } expect(testMultiLineString).toBeMultiLineStringGeometry() expect(testMultiLineString).toBeAnyGeometry() + expect(testMultiLineString).toBeValidGeoJSON() }) test('Empty coordinate', () => { @@ -145,6 +146,7 @@ describe('Valid Use Cases', () => { } expect(testMultiLineString).toBeMultiLineStringGeometry() expect(testMultiLineString).toBeAnyGeometry() + expect(testMultiLineString).toBeValidGeoJSON() }) test('Stress test with many points in many linestrings', () => { @@ -160,6 +162,7 @@ describe('Valid Use Cases', () => { } expect(testMultiLineString).toBeMultiLineStringGeometry() expect(testMultiLineString).toBeAnyGeometry() + expect(testMultiLineString).toBeValidGeoJSON() }) }) @@ -209,6 +212,7 @@ describe('Valid Use Cases', () => { } expect(testMultiLineString).toBeMultiLineStringGeometry() expect(testMultiLineString).toBeAnyGeometry() + expect(testMultiLineString).toBeValidGeoJSON() }) test.each([testMultiLineString1, testMultiLineString2, testMultiLineString3])( @@ -216,6 +220,7 @@ describe('Valid Use Cases', () => { (testMultiLineString) => { expect(testMultiLineString).toBeMultiLineStringGeometry() expect(testMultiLineString).toBeAnyGeometry() + expect(testMultiLineString).toBeValidGeoJSON() } ) }) @@ -234,6 +239,7 @@ describe('Valid Use Cases', () => { } expect(testMultiLineString).toBeMultiLineStringGeometry() expect(testMultiLineString).toBeAnyGeometry() + expect(testMultiLineString).toBeValidGeoJSON() }) test('3D Bounding Box', () => { @@ -249,6 +255,7 @@ describe('Valid Use Cases', () => { } expect(testMultiLineString).toBeMultiLineStringGeometry() expect(testMultiLineString).toBeAnyGeometry() + expect(testMultiLineString).toBeValidGeoJSON() }) test('Illogical Bounding Box', () => { @@ -264,6 +271,7 @@ describe('Valid Use Cases', () => { } expect(testMultiLineString).toBeMultiLineStringGeometry() expect(testMultiLineString).toBeAnyGeometry() + expect(testMultiLineString).toBeValidGeoJSON() }) test('Redundant Bounding Box', () => { @@ -279,6 +287,7 @@ describe('Valid Use Cases', () => { } expect(testMultiLineString).toBeMultiLineStringGeometry() expect(testMultiLineString).toBeAnyGeometry() + expect(testMultiLineString).toBeValidGeoJSON() }) }) }) @@ -290,6 +299,7 @@ describe('Inalid Use Cases', () => { (badInput) => { expect(badInput).not.toBeMultiLineStringGeometry() expect(badInput).not.toBeAnyGeometry() + expect(badInput).not.toBeValidGeoJSON() } ) }) @@ -304,6 +314,7 @@ describe('Inalid Use Cases', () => { } expect(testMultiLineString).not.toBeMultiLineStringGeometry() expect(testMultiLineString).not.toBeAnyGeometry() + expect(testMultiLineString).not.toBeValidGeoJSON() } ) }) @@ -317,6 +328,7 @@ describe('Inalid Use Cases', () => { } expect(testMultiLineString).not.toBeMultiLineStringGeometry() expect(testMultiLineString).not.toBeAnyGeometry() + expect(testMultiLineString).not.toBeValidGeoJSON() }) }) @@ -328,6 +340,7 @@ describe('Inalid Use Cases', () => { } expect(testMultiLineString).not.toBeMultiLineStringGeometry() expect(testMultiLineString).not.toBeAnyGeometry() + expect(testMultiLineString).not.toBeValidGeoJSON() }) }) @@ -339,6 +352,7 @@ describe('Inalid Use Cases', () => { } expect(testMultiLineString).not.toBeMultiLineStringGeometry() expect(testMultiLineString).not.toBeAnyGeometry() + expect(testMultiLineString).not.toBeValidGeoJSON() }) }) @@ -375,6 +389,7 @@ describe('Inalid Use Cases', () => { } expect(testMultiLineString).not.toBeMultiLineStringGeometry() expect(testMultiLineString).not.toBeAnyGeometry() + expect(testMultiLineString).not.toBeValidGeoJSON() }) test(`Contains: 'properties'`, () => { @@ -392,6 +407,7 @@ describe('Inalid Use Cases', () => { } expect(testMultiLineString).not.toBeMultiLineStringGeometry() expect(testMultiLineString).not.toBeAnyGeometry() + expect(testMultiLineString).not.toBeValidGeoJSON() }) test(`Contains: 'features'`, () => { @@ -418,6 +434,7 @@ describe('Inalid Use Cases', () => { } expect(testMultiLineString).not.toBeMultiLineStringGeometry() expect(testMultiLineString).not.toBeAnyGeometry() + expect(testMultiLineString).not.toBeValidGeoJSON() }) }) @@ -433,6 +450,7 @@ describe('Inalid Use Cases', () => { } expect(testMultiLineString).not.toBeMultiLineStringGeometry() expect(testMultiLineString).not.toBeAnyGeometry() + expect(testMultiLineString).not.toBeValidGeoJSON() }) test(`Missing: 'coordinates'`, () => { @@ -441,6 +459,7 @@ describe('Inalid Use Cases', () => { } expect(testMultiLineString).not.toBeMultiLineStringGeometry() expect(testMultiLineString).not.toBeAnyGeometry() + expect(testMultiLineString).not.toBeValidGeoJSON() }) }) @@ -467,6 +486,7 @@ describe('Inalid Use Cases', () => { } expect(testMultiLineString).not.toBePointGeometry() expect(testMultiLineString).not.toBeAnyGeometry() + expect(testMultiLineString).not.toBeValidGeoJSON() }) }) }) diff --git a/tests/geometries/toBeMultiPointGeometry.test.js b/tests/geometries/toBeMultiPointGeometry.test.js index df486db..08d3529 100644 --- a/tests/geometries/toBeMultiPointGeometry.test.js +++ b/tests/geometries/toBeMultiPointGeometry.test.js @@ -122,6 +122,7 @@ describe('Valid Use Cases', () => { } expect(testMultiPoint).toBeMultiPointGeometry() expect(testMultiPoint).toBeAnyGeometry() + expect(testMultiPoint).toBeValidGeoJSON() }) test('Empty coordinate', () => { @@ -131,6 +132,7 @@ describe('Valid Use Cases', () => { } expect(testMultiPoint).toBeMultiPointGeometry() expect(testMultiPoint).toBeAnyGeometry() + expect(testMultiPoint).toBeValidGeoJSON() }) }) @@ -169,6 +171,7 @@ describe('Valid Use Cases', () => { } expect(testMultiPoint).toBeMultiPointGeometry() expect(testMultiPoint).toBeAnyGeometry() + expect(testMultiPoint).toBeValidGeoJSON() }) test.each([testMultiPoint1, testMultiPoint2, testMultiPoint3])( @@ -176,6 +179,7 @@ describe('Valid Use Cases', () => { (testMultiPoint) => { expect(testMultiPoint).toBeMultiPointGeometry() expect(testMultiPoint).toBeAnyGeometry() + expect(testMultiPoint).toBeValidGeoJSON() } ) }) @@ -189,6 +193,7 @@ describe('Valid Use Cases', () => { } expect(testMultiPoint).toBeMultiPointGeometry() expect(testMultiPoint).toBeAnyGeometry() + expect(testMultiPoint).toBeValidGeoJSON() }) test('3D Bounding Box', () => { @@ -199,6 +204,7 @@ describe('Valid Use Cases', () => { } expect(testMultiPoint).toBeMultiPointGeometry() expect(testMultiPoint).toBeAnyGeometry() + expect(testMultiPoint).toBeValidGeoJSON() }) test('Illogical Bounding Box', () => { @@ -209,6 +215,7 @@ describe('Valid Use Cases', () => { } expect(testMultiPoint).toBeMultiPointGeometry() expect(testMultiPoint).toBeAnyGeometry() + expect(testMultiPoint).toBeValidGeoJSON() }) test('Redundant Bounding Box', () => { @@ -219,6 +226,7 @@ describe('Valid Use Cases', () => { } expect(testMultiPoint).toBeMultiPointGeometry() expect(testMultiPoint).toBeAnyGeometry() + expect(testMultiPoint).toBeValidGeoJSON() }) }) }) @@ -230,6 +238,7 @@ describe('Inalid Use Cases', () => { (badInput) => { expect(badInput).not.toBeMultiPointGeometry() expect(badInput).not.toBeAnyGeometry() + expect(badInput).not.toBeValidGeoJSON() } ) }) @@ -244,6 +253,7 @@ describe('Inalid Use Cases', () => { } expect(testMultiPoint).not.toBeMultiPointGeometry() expect(testMultiPoint).not.toBeAnyGeometry() + expect(testMultiPoint).not.toBeValidGeoJSON() } ) }) @@ -278,6 +288,7 @@ describe('Inalid Use Cases', () => { expect(testMultiPoint).not.toBeMultiPointGeometry() expect(testMultiPoint).not.toBeAnyGeometry() + expect(testMultiPoint).not.toBeValidGeoJSON() }) test(`Contains: 'properties'`, () => { @@ -294,6 +305,7 @@ describe('Inalid Use Cases', () => { expect(testMultiPoint).not.toBeMultiPointGeometry() expect(testMultiPoint).not.toBeAnyGeometry() + expect(testMultiPoint).not.toBeValidGeoJSON() }) test(`Contains: 'features'`, () => { @@ -318,6 +330,7 @@ describe('Inalid Use Cases', () => { } expect(testMultiPoint).not.toBeMultiPointGeometry() expect(testMultiPoint).not.toBeAnyGeometry() + expect(testMultiPoint).not.toBeValidGeoJSON() }) }) @@ -331,6 +344,7 @@ describe('Inalid Use Cases', () => { } expect(testMultiPoint).not.toBeMultiPointGeometry() expect(testMultiPoint).not.toBeAnyGeometry() + expect(testMultiPoint).not.toBeValidGeoJSON() }) test(`Missing: 'coordinates'`, () => { const testMultiPoint = { @@ -338,6 +352,7 @@ describe('Inalid Use Cases', () => { } expect(testMultiPoint).not.toBeMultiPointGeometry() expect(testMultiPoint).not.toBeAnyGeometry() + expect(testMultiPoint).not.toBeValidGeoJSON() }) }) @@ -359,6 +374,7 @@ describe('Inalid Use Cases', () => { } expect(testMultiPoint).not.toBeMultiPointGeometry() expect(testMultiPoint).not.toBeAnyGeometry() + expect(testMultiPoint).not.toBeValidGeoJSON() }) }) }) diff --git a/tests/geometries/toBeMultiPolygonGeometry.test.js b/tests/geometries/toBeMultiPolygonGeometry.test.js index 66346f7..abc3815 100644 --- a/tests/geometries/toBeMultiPolygonGeometry.test.js +++ b/tests/geometries/toBeMultiPolygonGeometry.test.js @@ -143,6 +143,7 @@ describe('Valid Use Cases', () => { test('Complex generic example works', () => { expect(genericMultiPolygonExample).toBeMultiPolygonGeometry() expect(genericMultiPolygonExample).toBeAnyGeometry() + expect(genericMultiPolygonExample).toBeValidGeoJSON() }) test('Good in range counterclockwise coordinates: %p', () => { @@ -152,6 +153,7 @@ describe('Valid Use Cases', () => { } expect(testMultiPolygon).toBeMultiPolygonGeometry() expect(testMultiPolygon).toBeAnyGeometry() + expect(testMultiPolygon).toBeValidGeoJSON() }) test('Good in range clockwise coordinates: %p', () => { @@ -161,6 +163,7 @@ describe('Valid Use Cases', () => { } expect(testMultiPolygon).toBeMultiPolygonGeometry() expect(testMultiPolygon).toBeAnyGeometry() + expect(testMultiPolygon).toBeValidGeoJSON() }) test('Good in range counterclockwise exterior with clockwise hole: %p', () => { @@ -170,6 +173,7 @@ describe('Valid Use Cases', () => { } expect(testMultiPolygon).toBeMultiPolygonGeometry() expect(testMultiPolygon).toBeAnyGeometry() + expect(testMultiPolygon).toBeValidGeoJSON() }) test('Good in range counterclockwise exterior with counterclockwise hole: %p', () => { @@ -179,6 +183,7 @@ describe('Valid Use Cases', () => { } expect(testMultiPolygon).toBeMultiPolygonGeometry() expect(testMultiPolygon).toBeAnyGeometry() + expect(testMultiPolygon).toBeValidGeoJSON() }) test('Good in range clockwise exterior with clockwise hole: %p', () => { @@ -188,6 +193,7 @@ describe('Valid Use Cases', () => { } expect(testMultiPolygon).toBeMultiPolygonGeometry() expect(testMultiPolygon).toBeAnyGeometry() + expect(testMultiPolygon).toBeValidGeoJSON() }) test('Good in range clockwise exterior with counterclockwise hole: %p', () => { @@ -197,6 +203,7 @@ describe('Valid Use Cases', () => { } expect(testMultiPolygon).toBeMultiPolygonGeometry() expect(testMultiPolygon).toBeAnyGeometry() + expect(testMultiPolygon).toBeValidGeoJSON() }) test('Empty coordinate', () => { @@ -206,6 +213,7 @@ describe('Valid Use Cases', () => { } expect(testMultiPolygon).toBeMultiPolygonGeometry() expect(testMultiPolygon).toBeAnyGeometry() + expect(testMultiPolygon).toBeValidGeoJSON() }) test('Cutting the antimeridian', () => { @@ -234,6 +242,7 @@ describe('Valid Use Cases', () => { } expect(testMultiPolygon).toBeMultiPolygonGeometry() expect(testMultiPolygon).toBeAnyGeometry() + expect(testMultiPolygon).toBeValidGeoJSON() }) test('Spanning the antimeridian', () => { @@ -253,6 +262,7 @@ describe('Valid Use Cases', () => { } expect(testMultiPolygon).toBeMultiPolygonGeometry() expect(testMultiPolygon).toBeAnyGeometry() + expect(testMultiPolygon).toBeValidGeoJSON() }) test('Stress test with many points in many holes', () => { @@ -272,6 +282,7 @@ describe('Valid Use Cases', () => { } expect(testMultiPolygon).toBeMultiPolygonGeometry() expect(testMultiPolygon).toBeAnyGeometry() + expect(testMultiPolygon).toBeValidGeoJSON() }) }) @@ -301,6 +312,7 @@ describe('Valid Use Cases', () => { } expect(testMultiPolygon).toBeMultiPolygonGeometry() expect(testMultiPolygon).toBeAnyGeometry() + expect(testMultiPolygon).toBeValidGeoJSON() }) test.each([testMultiPolygon1, testMultiPolygon2, testMultiPolygon3])( @@ -308,6 +320,7 @@ describe('Valid Use Cases', () => { (testMultiPolygon) => { expect(testMultiPolygon).toBeMultiPolygonGeometry() expect(testMultiPolygon).toBeAnyGeometry() + expect(testMultiPolygon).toBeValidGeoJSON() } ) }) @@ -342,6 +355,7 @@ describe('Valid Use Cases', () => { } expect(testMultiPolygon).toBeMultiPolygonGeometry() expect(testMultiPolygon).toBeAnyGeometry() + expect(testMultiPolygon).toBeValidGeoJSON() }) test('Redundant Interior ring all the same point', () => { @@ -351,6 +365,7 @@ describe('Valid Use Cases', () => { } expect(testMultiPolygon).toBeMultiPolygonGeometry() expect(testMultiPolygon).toBeAnyGeometry() + expect(testMultiPolygon).toBeValidGeoJSON() }) test('Interior rings outside exterior rings', () => { @@ -360,6 +375,7 @@ describe('Valid Use Cases', () => { } expect(testMultiPolygon).toBeMultiPolygonGeometry() expect(testMultiPolygon).toBeAnyGeometry() + expect(testMultiPolygon).toBeValidGeoJSON() }) test('Multiple polygons Interior rings outside exterior rings', () => { @@ -372,6 +388,7 @@ describe('Valid Use Cases', () => { } expect(testMultiPolygon).toBeMultiPolygonGeometry() expect(testMultiPolygon).toBeAnyGeometry() + expect(testMultiPolygon).toBeValidGeoJSON() }) }) @@ -394,6 +411,7 @@ describe('Valid Use Cases', () => { } expect(testMultiPolygon).toBeMultiPolygonGeometry() expect(testMultiPolygon).toBeAnyGeometry() + expect(testMultiPolygon).toBeValidGeoJSON() }) test('3D Bounding Box', () => { @@ -414,6 +432,7 @@ describe('Valid Use Cases', () => { } expect(testMultiPolygon).toBeMultiPolygonGeometry() expect(testMultiPolygon).toBeAnyGeometry() + expect(testMultiPolygon).toBeValidGeoJSON() }) test('Illogical Bounding Box', () => { @@ -434,6 +453,7 @@ describe('Valid Use Cases', () => { } expect(testMultiPolygon).toBeMultiPolygonGeometry() expect(testMultiPolygon).toBeAnyGeometry() + expect(testMultiPolygon).toBeValidGeoJSON() }) test('Redundant Bounding Box', () => { @@ -454,6 +474,7 @@ describe('Valid Use Cases', () => { } expect(testMultiPolygon).toBeMultiPolygonGeometry() expect(testMultiPolygon).toBeAnyGeometry() + expect(testMultiPolygon).toBeValidGeoJSON() }) }) }) @@ -465,6 +486,7 @@ describe('Inalid Use Cases', () => { (badInput) => { expect(badInput).not.toBeMultiPolygonGeometry() expect(badInput).not.toBeAnyGeometry() + expect(badInput).not.toBeValidGeoJSON() } ) }) @@ -479,6 +501,7 @@ describe('Inalid Use Cases', () => { } expect(testMultiPolygon).not.toBeMultiPolygonGeometry() expect(testMultiPolygon).not.toBeAnyGeometry() + expect(testMultiPolygon).not.toBeValidGeoJSON() } ) @@ -492,6 +515,7 @@ describe('Inalid Use Cases', () => { } expect(testMultiPolygon).not.toBeMultiPolygonGeometry() expect(testMultiPolygon).not.toBeAnyGeometry() + expect(testMultiPolygon).not.toBeValidGeoJSON() } ) }) @@ -507,6 +531,7 @@ describe('Inalid Use Cases', () => { } expect(testMultiPolygon).not.toBeMultiPolygonGeometry() expect(testMultiPolygon).not.toBeAnyGeometry() + expect(testMultiPolygon).not.toBeValidGeoJSON() } ) }) @@ -519,6 +544,7 @@ describe('Inalid Use Cases', () => { } expect(testMultiPolygon).not.toBeMultiPolygonGeometry() expect(testMultiPolygon).not.toBeAnyGeometry() + expect(testMultiPolygon).not.toBeValidGeoJSON() }) test('coordinates: [[[0, 0], [1, 1]]]', () => { @@ -535,6 +561,7 @@ describe('Inalid Use Cases', () => { } expect(testMultiPolygon).not.toBeMultiPolygonGeometry() expect(testMultiPolygon).not.toBeAnyGeometry() + expect(testMultiPolygon).not.toBeValidGeoJSON() }) test('coordinates: [[[0, 0], [1, 1]], [[1, 0]]]', () => { @@ -552,6 +579,7 @@ describe('Inalid Use Cases', () => { } expect(testMultiPolygon).not.toBeMultiPolygonGeometry() expect(testMultiPolygon).not.toBeAnyGeometry() + expect(testMultiPolygon).not.toBeValidGeoJSON() }) test('coordinates: [[[0, 0], [0, 1], [1, 1], [1, 0], [0, 0]]], [[[0, 0], [1, 1]], [[1, 0]]]]', () => { @@ -578,6 +606,7 @@ describe('Inalid Use Cases', () => { } expect(testMultiPolygon).not.toBeMultiPolygonGeometry() expect(testMultiPolygon).not.toBeAnyGeometry() + expect(testMultiPolygon).not.toBeValidGeoJSON() }) }) @@ -596,6 +625,7 @@ describe('Inalid Use Cases', () => { } expect(testMultiPolygon).not.toBeMultiPolygonGeometry() expect(testMultiPolygon).not.toBeAnyGeometry() + expect(testMultiPolygon).not.toBeValidGeoJSON() }) test('Good exterior, bad hole', () => { @@ -605,6 +635,7 @@ describe('Inalid Use Cases', () => { } expect(testMultiPolygon).not.toBeMultiPolygonGeometry() expect(testMultiPolygon).not.toBeAnyGeometry() + expect(testMultiPolygon).not.toBeValidGeoJSON() }) test('Good exterior, two bad holes', () => { @@ -616,6 +647,7 @@ describe('Inalid Use Cases', () => { } expect(testMultiPolygon).not.toBeMultiPolygonGeometry() expect(testMultiPolygon).not.toBeAnyGeometry() + expect(testMultiPolygon).not.toBeValidGeoJSON() }) test('Bad exterior, good hole', () => { @@ -625,6 +657,7 @@ describe('Inalid Use Cases', () => { } expect(testMultiPolygon).not.toBeMultiPolygonGeometry() expect(testMultiPolygon).not.toBeAnyGeometry() + expect(testMultiPolygon).not.toBeValidGeoJSON() }) test('Bad exterior, two good holes', () => { @@ -636,6 +669,7 @@ describe('Inalid Use Cases', () => { } expect(testMultiPolygon).not.toBeMultiPolygonGeometry() expect(testMultiPolygon).not.toBeAnyGeometry() + expect(testMultiPolygon).not.toBeValidGeoJSON() }) }) @@ -647,6 +681,7 @@ describe('Inalid Use Cases', () => { } expect(testMultiPolygon).not.toBeMultiPolygonGeometry() expect(testMultiPolygon).not.toBeAnyGeometry() + expect(testMultiPolygon).not.toBeValidGeoJSON() }) }) @@ -658,6 +693,7 @@ describe('Inalid Use Cases', () => { } expect(testMultiPolygon).not.toBeMultiPolygonGeometry() expect(testMultiPolygon).not.toBeAnyGeometry() + expect(testMultiPolygon).not.toBeValidGeoJSON() }) }) @@ -673,6 +709,7 @@ describe('Inalid Use Cases', () => { } expect(testMultiPolygon).not.toBeMultiPolygonGeometry() expect(testMultiPolygon).not.toBeAnyGeometry() + expect(testMultiPolygon).not.toBeValidGeoJSON() }) test(`Contains: 'properties'`, () => { @@ -685,6 +722,7 @@ describe('Inalid Use Cases', () => { } expect(testMultiPolygon).not.toBeMultiPolygonGeometry() expect(testMultiPolygon).not.toBeAnyGeometry() + expect(testMultiPolygon).not.toBeValidGeoJSON() }) test(`Contains: 'features'`, () => { @@ -706,6 +744,7 @@ describe('Inalid Use Cases', () => { } expect(testMultiPolygon).not.toBeMultiPolygonGeometry() expect(testMultiPolygon).not.toBeAnyGeometry() + expect(testMultiPolygon).not.toBeValidGeoJSON() }) }) @@ -716,6 +755,7 @@ describe('Inalid Use Cases', () => { } expect(testMultiPolygon).not.toBeMultiPolygonGeometry() expect(testMultiPolygon).not.toBeAnyGeometry() + expect(testMultiPolygon).not.toBeValidGeoJSON() }) test(`Missing: 'coordinates'`, () => { @@ -724,6 +764,7 @@ describe('Inalid Use Cases', () => { } expect(testMultiPolygon).not.toBeMultiPolygonGeometry() expect(testMultiPolygon).not.toBeAnyGeometry() + expect(testMultiPolygon).not.toBeValidGeoJSON() }) }) @@ -755,6 +796,7 @@ describe('Inalid Use Cases', () => { } expect(testMultiPolygon).not.toBeMultiPolygonGeometry() expect(testMultiPolygon).not.toBeAnyGeometry() + expect(testMultiPolygon).not.toBeValidGeoJSON() }) }) }) diff --git a/tests/geometries/toBePointGeometry.test.js b/tests/geometries/toBePointGeometry.test.js index a6c04ad..f9089aa 100644 --- a/tests/geometries/toBePointGeometry.test.js +++ b/tests/geometries/toBePointGeometry.test.js @@ -42,6 +42,7 @@ describe('Valid Use Cases', () => { } expect(testPoint).toBePointGeometry() expect(testPoint).toBeAnyGeometry() + expect(testPoint).toBeValidGeoJSON() }) test('Good 3D coordinate', () => { @@ -51,6 +52,7 @@ describe('Valid Use Cases', () => { } expect(testPoint).toBePointGeometry() expect(testPoint).toBeAnyGeometry() + expect(testPoint).toBeValidGeoJSON() }) test('Empty coordinate', () => { @@ -60,6 +62,7 @@ describe('Valid Use Cases', () => { } expect(testPoint).toBePointGeometry() expect(testPoint).toBeAnyGeometry() + expect(testPoint).toBeValidGeoJSON() }) }) @@ -89,11 +92,13 @@ describe('Valid Use Cases', () => { } expect(testPoint).toBePointGeometry() expect(testPoint).toBeAnyGeometry() + expect(testPoint).toBeValidGeoJSON() }) test.each([testPoint1, testPoint2, testPoint3])('Non-alphanumeric ID', (testPoint) => { expect(testPoint).toBePointGeometry() expect(testPoint).toBeAnyGeometry() + expect(testPoint).toBeValidGeoJSON() }) }) @@ -106,6 +111,7 @@ describe('Valid Use Cases', () => { } expect(testPoint).toBePointGeometry() expect(testPoint).toBeAnyGeometry() + expect(testPoint).toBeValidGeoJSON() }) test('3D Bounding Box', () => { @@ -116,6 +122,7 @@ describe('Valid Use Cases', () => { } expect(testPoint).toBePointGeometry() expect(testPoint).toBeAnyGeometry() + expect(testPoint).toBeValidGeoJSON() }) test('Illogical Bounding Box', () => { @@ -126,6 +133,7 @@ describe('Valid Use Cases', () => { } expect(testPoint).toBePointGeometry() expect(testPoint).toBeAnyGeometry() + expect(testPoint).toBeValidGeoJSON() }) test('Redundant Bounding Box', () => { @@ -136,6 +144,7 @@ describe('Valid Use Cases', () => { } expect(testPoint).toBePointGeometry() expect(testPoint).toBeAnyGeometry() + expect(testPoint).toBeValidGeoJSON() }) }) }) @@ -145,6 +154,7 @@ describe('Inalid Use Cases', () => { test.each([...invalidInputValues])('expect(%p).not.toBePointGeometry()', (badInput) => { expect(badInput).not.toBePointGeometry() expect(badInput).not.toBeAnyGeometry() + expect(badInput).not.toBeValidGeoJSON() }) }) @@ -158,6 +168,7 @@ describe('Inalid Use Cases', () => { } expect(testPoint).not.toBePointGeometry() expect(testPoint).not.toBeAnyGeometry() + expect(testPoint).not.toBeValidGeoJSON() } ) }) @@ -185,6 +196,7 @@ describe('Inalid Use Cases', () => { } expect(testPoint).not.toBePointGeometry() expect(testPoint).not.toBeAnyGeometry() + expect(testPoint).not.toBeValidGeoJSON() }) test(`Contains: 'properties'`, () => { @@ -197,6 +209,7 @@ describe('Inalid Use Cases', () => { } expect(testPoint).not.toBePointGeometry() expect(testPoint).not.toBeAnyGeometry() + expect(testPoint).not.toBeValidGeoJSON() }) test(`Contains: 'features'`, () => { @@ -218,6 +231,7 @@ describe('Inalid Use Cases', () => { } expect(testPoint).not.toBePointGeometry() expect(testPoint).not.toBeAnyGeometry() + expect(testPoint).not.toBeValidGeoJSON() }) }) @@ -228,6 +242,7 @@ describe('Inalid Use Cases', () => { } expect(testPoint).not.toBePointGeometry() expect(testPoint).not.toBeAnyGeometry() + expect(testPoint).not.toBeValidGeoJSON() }) test(`Missing: 'coordinates'`, () => { @@ -236,6 +251,7 @@ describe('Inalid Use Cases', () => { } expect(testPoint).not.toBePointGeometry() expect(testPoint).not.toBeAnyGeometry() + expect(testPoint).not.toBeValidGeoJSON() }) }) @@ -257,6 +273,7 @@ describe('Inalid Use Cases', () => { } expect(testPoint).not.toBePointGeometry() expect(testPoint).not.toBeAnyGeometry() + expect(testPoint).not.toBeValidGeoJSON() }) }) }) diff --git a/tests/geometries/toBePolygonGeometry.test.js b/tests/geometries/toBePolygonGeometry.test.js index f9ae5a3..2202bbf 100644 --- a/tests/geometries/toBePolygonGeometry.test.js +++ b/tests/geometries/toBePolygonGeometry.test.js @@ -116,6 +116,7 @@ describe('Valid Use Cases', () => { } expect(testPolygon).toBePolygonGeometry() expect(testPolygon).toBeAnyGeometry() + expect(testPolygon).toBeValidGeoJSON() }) test('Good in range clockwise coordinates: %p', () => { @@ -125,6 +126,7 @@ describe('Valid Use Cases', () => { } expect(testPolygon).toBePolygonGeometry() expect(testPolygon).toBeAnyGeometry() + expect(testPolygon).toBeValidGeoJSON() }) test('Good in range counterclockwise exterior with clockwise hole: %p', () => { @@ -134,6 +136,7 @@ describe('Valid Use Cases', () => { } expect(testPolygon).toBePolygonGeometry() expect(testPolygon).toBeAnyGeometry() + expect(testPolygon).toBeValidGeoJSON() }) test('Good in range counterclockwise exterior with counterclockwise hole: %p', () => { @@ -143,6 +146,7 @@ describe('Valid Use Cases', () => { } expect(testPolygon).toBePolygonGeometry() expect(testPolygon).toBeAnyGeometry() + expect(testPolygon).toBeValidGeoJSON() }) test('Good in range clockwise exterior with clockwise hole: %p', () => { @@ -152,6 +156,7 @@ describe('Valid Use Cases', () => { } expect(testPolygon).toBePolygonGeometry() expect(testPolygon).toBeAnyGeometry() + expect(testPolygon).toBeValidGeoJSON() }) test('Good in range clockwise exterior with counterclockwise hole: %p', () => { @@ -161,6 +166,7 @@ describe('Valid Use Cases', () => { } expect(testPolygon).toBePolygonGeometry() expect(testPolygon).toBeAnyGeometry() + expect(testPolygon).toBeValidGeoJSON() }) test('Empty coordinate', () => { @@ -170,6 +176,7 @@ describe('Valid Use Cases', () => { } expect(testPolygon).toBePolygonGeometry() expect(testPolygon).toBeAnyGeometry() + expect(testPolygon).toBeValidGeoJSON() }) test('Spanning the antimeridian', () => { @@ -189,6 +196,7 @@ describe('Valid Use Cases', () => { } expect(testPolygon).toBePolygonGeometry() expect(testPolygon).toBeAnyGeometry() + expect(testPolygon).toBeValidGeoJSON() }) test('Stress test with many points in many holes', () => { @@ -205,6 +213,7 @@ describe('Valid Use Cases', () => { } expect(testPolygon).toBePolygonGeometry() expect(testPolygon).toBeAnyGeometry() + expect(testPolygon).toBeValidGeoJSON() }) }) @@ -234,6 +243,7 @@ describe('Valid Use Cases', () => { } expect(testPolygon).toBePolygonGeometry() expect(testPolygon).toBeAnyGeometry() + expect(testPolygon).toBeValidGeoJSON() }) test.each([testPolygon1, testPolygon2, testPolygon3])( @@ -241,6 +251,7 @@ describe('Valid Use Cases', () => { (testPolygon) => { expect(testPolygon).toBePolygonGeometry() expect(testPolygon).toBeAnyGeometry() + expect(testPolygon).toBeValidGeoJSON() } ) }) @@ -275,6 +286,7 @@ describe('Valid Use Cases', () => { } expect(testPolygon).toBePolygonGeometry() expect(testPolygon).toBeAnyGeometry() + expect(testPolygon).toBeValidGeoJSON() }) test('Redundant Interior ring all the same point', () => { @@ -284,6 +296,7 @@ describe('Valid Use Cases', () => { } expect(testPolygon).toBePolygonGeometry() expect(testPolygon).toBeAnyGeometry() + expect(testPolygon).toBeValidGeoJSON() }) test('Interior rings outside exterior rings', () => { @@ -293,6 +306,7 @@ describe('Valid Use Cases', () => { } expect(testPolygon).toBePolygonGeometry() expect(testPolygon).toBeAnyGeometry() + expect(testPolygon).toBeValidGeoJSON() }) }) @@ -313,6 +327,7 @@ describe('Valid Use Cases', () => { } expect(testPolygon).toBePolygonGeometry() expect(testPolygon).toBeAnyGeometry() + expect(testPolygon).toBeValidGeoJSON() }) test('3D Bounding Box', () => { @@ -331,6 +346,7 @@ describe('Valid Use Cases', () => { } expect(testPolygon).toBePolygonGeometry() expect(testPolygon).toBeAnyGeometry() + expect(testPolygon).toBeValidGeoJSON() }) test('Illogical Bounding Box', () => { @@ -349,6 +365,7 @@ describe('Valid Use Cases', () => { } expect(testPolygon).toBePolygonGeometry() expect(testPolygon).toBeAnyGeometry() + expect(testPolygon).toBeValidGeoJSON() }) test('Redundant Bounding Box', () => { @@ -367,6 +384,7 @@ describe('Valid Use Cases', () => { } expect(testPolygon).toBePolygonGeometry() expect(testPolygon).toBeAnyGeometry() + expect(testPolygon).toBeValidGeoJSON() }) }) }) @@ -376,6 +394,7 @@ describe('Inalid Use Cases', () => { test.each([...invalidInputValues])('expect(%p).not.toBePolygonGeometry()', (badInput) => { expect(badInput).not.toBePolygonGeometry() expect(badInput).not.toBeAnyGeometry() + expect(badInput).not.toBeValidGeoJSON() }) }) @@ -389,6 +408,7 @@ describe('Inalid Use Cases', () => { } expect(testPolygon).not.toBePolygonGeometry() expect(testPolygon).not.toBeAnyGeometry() + expect(testPolygon).not.toBeValidGeoJSON() } ) }) @@ -404,6 +424,7 @@ describe('Inalid Use Cases', () => { } expect(testPolygon).not.toBePolygonGeometry() expect(testPolygon).not.toBeAnyGeometry() + expect(testPolygon).not.toBeValidGeoJSON() } ) }) @@ -416,6 +437,7 @@ describe('Inalid Use Cases', () => { } expect(testPolygon).not.toBePolygonGeometry() expect(testPolygon).not.toBeAnyGeometry() + expect(testPolygon).not.toBeValidGeoJSON() }) test('coordinates: [[[0, 0], [1, 1]]]', () => { @@ -430,6 +452,7 @@ describe('Inalid Use Cases', () => { } expect(testPolygon).not.toBePolygonGeometry() expect(testPolygon).not.toBeAnyGeometry() + expect(testPolygon).not.toBeValidGeoJSON() }) test('coordinates: [[[0, 0], [1, 1]], [[1, 0]]]', () => { @@ -445,6 +468,7 @@ describe('Inalid Use Cases', () => { } expect(testPolygon).not.toBePolygonGeometry() expect(testPolygon).not.toBeAnyGeometry() + expect(testPolygon).not.toBeValidGeoJSON() }) }) @@ -463,6 +487,7 @@ describe('Inalid Use Cases', () => { } expect(testPolygon).not.toBePolygonGeometry() expect(testPolygon).not.toBeAnyGeometry() + expect(testPolygon).not.toBeValidGeoJSON() }) test('Good exterior, bad hole', () => { @@ -472,6 +497,7 @@ describe('Inalid Use Cases', () => { } expect(testPolygon).not.toBePolygonGeometry() expect(testPolygon).not.toBeAnyGeometry() + expect(testPolygon).not.toBeValidGeoJSON() }) test('Good exterior, two bad holes', () => { @@ -485,6 +511,7 @@ describe('Inalid Use Cases', () => { } expect(testPolygon).not.toBePolygonGeometry() expect(testPolygon).not.toBeAnyGeometry() + expect(testPolygon).not.toBeValidGeoJSON() }) test('Bad exterior, good hole', () => { @@ -494,6 +521,7 @@ describe('Inalid Use Cases', () => { } expect(testPolygon).not.toBePolygonGeometry() expect(testPolygon).not.toBeAnyGeometry() + expect(testPolygon).not.toBeValidGeoJSON() }) test('Bad exterior, two good holes', () => { @@ -503,6 +531,7 @@ describe('Inalid Use Cases', () => { } expect(testPolygon).not.toBePolygonGeometry() expect(testPolygon).not.toBeAnyGeometry() + expect(testPolygon).not.toBeValidGeoJSON() }) }) @@ -514,6 +543,7 @@ describe('Inalid Use Cases', () => { } expect(testPolygon).not.toBePolygonGeometry() expect(testPolygon).not.toBeAnyGeometry() + expect(testPolygon).not.toBeValidGeoJSON() }) }) @@ -540,6 +570,7 @@ describe('Inalid Use Cases', () => { } expect(testPolygon).not.toBePolygonGeometry() expect(testPolygon).not.toBeAnyGeometry() + expect(testPolygon).not.toBeValidGeoJSON() }) test(`Contains: 'properties'`, () => { @@ -552,6 +583,7 @@ describe('Inalid Use Cases', () => { } expect(testPolygon).not.toBePolygonGeometry() expect(testPolygon).not.toBeAnyGeometry() + expect(testPolygon).not.toBeValidGeoJSON() }) test(`Contains: 'features'`, () => { @@ -573,6 +605,7 @@ describe('Inalid Use Cases', () => { } expect(testPolygon).not.toBePolygonGeometry() expect(testPolygon).not.toBeAnyGeometry() + expect(testPolygon).not.toBeValidGeoJSON() }) }) @@ -583,6 +616,7 @@ describe('Inalid Use Cases', () => { } expect(testPolygon).not.toBePolygonGeometry() expect(testPolygon).not.toBeAnyGeometry() + expect(testPolygon).not.toBeValidGeoJSON() }) test(`Missing: 'coordinates'`, () => { @@ -591,6 +625,7 @@ describe('Inalid Use Cases', () => { } expect(testPolygon).not.toBePolygonGeometry() expect(testPolygon).not.toBeAnyGeometry() + expect(testPolygon).not.toBeValidGeoJSON() }) }) @@ -620,6 +655,7 @@ describe('Inalid Use Cases', () => { } expect(testPolygon).not.toBePolygonGeometry() expect(testPolygon).not.toBeAnyGeometry() + expect(testPolygon).not.toBeValidGeoJSON() }) }) }) diff --git a/tests/matchers.test.js b/tests/matchers.test.js index 1dd0c26..90a169d 100644 --- a/tests/matchers.test.js +++ b/tests/matchers.test.js @@ -30,15 +30,21 @@ describe('Coordinate Matchers Exported', () => { }) }) +describe('FeatureCollection Matchers Exported', () => { + test('toBeFeatureCollection', () => { + expect('toBeFeatureCollection' in matchers.featureCollections).toBeTruthy() + }) +}) + describe('Feature Matchers Exported', () => { test('toBeFeature', () => { expect('toBeFeature' in matchers.features).toBeTruthy() }) }) -describe('FeatureCollection Matchers Exported', () => { - test('toBeFeatureCollection', () => { - expect('toBeFeatureCollection' in matchers.featureCollections).toBeTruthy() +describe('Functional Matchers Exported', () => { + test('toBeValidGeoJSON', () => { + expect('toBeValidGeoJSON' in matchers.functional).toBeTruthy() }) })