Functional

Matchers. Functional

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

Methods

(static) toBeValidGeoJSON(geoObject)

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]
    }]
}

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()
})
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()
})
Parameters:
Name Type Description
geoObject object Any GeoJSON Geometry, Feature, or FeatureCollection object