chai-geojson
This plugin extends existing chaijs APIs and introduces new ones for testing GeoJSON elegantly. It provides brief syntax for:
- type assertion
- geographic area and length assertion
Installation
- NodeJS
npm install chai-geojson --save-dev
Usage
- NodeJS
const chai = ;chai;const expect = chaiexpect;const assert = chaiassert;const should = chai;/*** Do your tests with the following APIs.*/
API
See test cases for complete use examples.
Expect / Should
-
.a(type)
- @Param {String} type
The a
assertion can be used to assert a GeoJSON object’s type and its geometry coordinates if there is any. Noted this doesn't recursively iterate each features in a FeatureCollection or assert the geometry in a Feature.
Supported types:
- FeatureCollection
- Feature
- Geometry
- Point
- MultiPoint
- LineString
- MultiLineString
- Polygon
- MultiPolygon
tobe;tobe;nottobe;geojsonshouldbe;geojsonshouldnotbe;
- length
Sets the geomLength
flag later used as a chain precursor to a value comparison for the geographic length.
tohavelengthabove2;
-
.lengthOf(value[, precision])
-
@param {Number} value expected length value in meters
-
@param {Number} [precision=0] difference tolerance in percentage of the geographic length
Asserts that the length of LineString feature/geometry has the expected value.
tohave;nottohave;
- area
Sets the geomArea
flag later used as a chain precursor to a value comparison for the geographic area.
tohaveareabelow2000;
-
.areaOf(value[, precision])
-
@param {Number} value expected area value in square meters
-
@param {Number} [precision=0] difference tolerance in percentage of the geographic area
Asserts that the area of polygon feature/geometry has the expected value.
tohave;
-
.equal(value[, precision])
-
@param {Number} value expected value in meters for length or in square meters for square meters
-
@param {Number} [precision=0] difference tolerance in percentage of the expected value
The equal
assertion can be used to assert whether the length or area of a geojson feature/geometry is equal to the expected value.
tohavearea;tohavelength;
-
.above(value)
-
@param {Number} value expected value in meters for length or in square meters for area
The above
assertion can be used to assert whether the length or area of a geojson feature/geometry is above the given value.
tohaveareaabove500;tohavelengthabove250;
-
.least(value)
-
@param {Number} value expected value in meters for length or in square meters for area
The above
assertion can be used to assert whether the length or area of a geojson feature/geometry is at least the given value.
tohaveareaat;tohavelengthat;
-
.most(value)
-
@param {Number} value expected value in meters for length or in square meters for area
The above
assertion can be used to assert whether the length or area of a geojson feature/geometry is at most the given value.
tohaveareaat;tohavelengthat;
-
.below(value)
-
@param {Number} value expected value in meters for length or in square meters for area
The above
assertion can be used to assert whether the length or area of a geojson feature/geometry is below the given value.
tohaveareabelow500;tohavelengthbelow250;
-
.within(lower, upper)
-
@param {Number} lower expected lower bound of input value
-
@param {Number} upper expected upper bound of input value
The within
assertion can be used to assert whether the length or area of a geojson feature/geometry is within the given range.
tohavearea;tohavelength;
Assert
-
.typeOf(type)
- @Param {String} type
Same as .a(type)
in expect / should style.
assert;
-
.notTypeOf(type)
- @Param {String} type
Same as .not.a(type)
in expect / should style.
assert;
Lincense
MIT