A set of matchers related to validating feature objects.
Methods
(static) toBeFeature(featureObject, geometryType)
- Source:
- See:
Verifies an object is a valid GeoJSON Feature. This object requires a "type"
member that must equal 'Feature', a "geometry" member that contains either
one of the seven valid GeoJSON geometry objects or an empty array, and a
"properties" member that is either an object of any composition or null.
Foreign members are allowed with the exception of 'coordinates',
'geometries', 'properties', or 'features'. If present, bounding boxes must
be valid.
Examples
const testFeature = {
"type": "Feature",
"bbox": [-10.0, -10.0, 10.0, 10.0],
"geometry": {
"type": "Polygon",
"coordinates": [
[
[-10.0, -10.0],
[10.0, -10.0],
[10.0, 10.0],
[-10.0, -10.0]
]
]
},
"properties": {
"prop0": "value0",
"prop1": {
"this": "that"
}
}
}
test('Object is valid GeoJSON Feature', () => {
expect(testFeature).toBeFeature()
expect(testFeature).toBeFeature('Polygon')
})
const multiPoint = {
type: "MultiPoint",
coordinates: [
[101.0, 0.0],
[102.0, 1.0]
]
}
test('Object is NOT valid GeoJSON Geometry Object', () => {
expect(multiPoint).not.toBeFeature()
expect(testFeature).not.toBeFeature('LineString')
expect(testFeature.geometry).not.toBeFeature('Polygon')
})
Parameters:
Name | Type | Description |
---|---|---|
featureObject |
object | any GeoJSON Feature object |
geometryType |
string | Optional string representing one of the seven GeoJSON geometry types |
(static) toHaveID(featureObject, SearchIDopt)
- Source:
- See:
Checks if a GeoJSON Feature has an ID. Passes if the Feature object has any
ID (no argument provided), or if the ID exactly matches the optional
argument (single string, number, or RegExp provided), or any value within an
array of any combination of strings, numbers, or RegExp. The test fails if
the object does not have an ID, or if it has an ID that does not match the
SearchID.
Examples
const testFeature1 = {
type: 'Feature',
id: 'f1',
geometry: {...},
properties: {...}
}
test('Feature Has an ID', () => {
expect(testFeature1).toHaveID()
expect(testFeature1).toHaveID([])
expect(testFeature1).toHaveID('f1')
expect(testFeature1).toHaveID([1, 'F', 'F12', /[a-z]+[0-9]+/])
expect(testFeature1).not.toHaveID('f2')
expect(testFeature1).not.toHaveID([1, 'F', 'F12', /SomeID/])
})
const testFeature2 = {
type: 'Feature',
geometry: {...},
properties: {...}
}
test('Feature Does not Have an ID', () => {
expect(testFeature2).not.toHaveID()
expect(testFeature2).not.toHaveID(2)
})
Parameters:
Name | Type | Attributes | Description |
---|---|---|---|
featureObject |
object | any GeoJSON Feature object | |
SearchID |
string | number | RegExp | Array.<string> | Array.<number> | Array.<RegExp> | <optional> |
Specific value or array of possible values to search for. |
(static) toHaveNumericID(featureObject, SearchIDopt)
- Source:
- See:
Checks if a GeoJSON Feature has a numeric ID. Passes if the Feature object
has any numeric ID (no argument provided), or if the ID exactly matches the
optional argument (single number or RegExp provided), or any value within an
array of any combination of numbers or RegExp. The test fails if the object
does not have an ID, or if it has an ID that does not match the SearchID.
Passing a string type to SearchID will not pass the test, even if the ID
exactly matches.
Examples
const testFeature = {
type: 'Feature',
id: 456,
geometry: {...},
properties: {...}
}
test('Feature Has an ID', () => {
expect(testFeature).toHaveNumericID()
expect(testFeature).toHaveNumericID(456)
expect(testFeature).toHaveNumericID([1, 123, 345, /[a-z]+[0-9]+/])
})
const testFeatureNoID = {
type: 'Feature',
geometry: {...},
properties: {...}
}
const testFeatureStringID = {
type: 'Feature',
id: 'f1,
geometry: {...},
properties: {...}
}
test('Feature Does not Have an ID', () => {
expect(testFeatureNoID).not.toHaveNumericID()
expect(testFeatureStringID).not.toHaveNumericID()
expect(testFeatureStringID).not.toHaveNumericID('f1')
})
Parameters:
Name | Type | Attributes | Description |
---|---|---|---|
featureObject |
object | any GeoJSON Feature object | |
SearchID |
number | RegExp | Array.<number> | Array.<RegExp> | <optional> |
Specific value or array of possible values to search for. |
(static) toHaveStringID(featureObject, SearchIDopt)
- Source:
- See:
Checks if a GeoJSON Feature has a string ID. Passes if the Feature object
has any string ID (no argument provided), or if the ID exactly matches the
optional argument (single string or RegExp provided), or any value within an
array of any combination of strings or RegExp. The test fails if the object
does not have an ID, or if it has an ID that does not match the SearchID.
Passing a number type to SearchID will not pass the test, even if the ID
exactly matches.
Examples
const testFeature = {
type: 'Feature',
id: 'f1',
geometry: {...},
properties: {...}
}
test('Feature Has an ID', () => {
expect(testFeature).toHaveStringID()
expect(testFeature).toHaveStringID([])
expect(testFeature).toHaveStringID('f1')
expect(testFeature).toHaveStringID(['1', 'F', 'F12', /[a-z]+[0-9]+/])
})
const testFeatureNoID = {
type: 'Feature',
geometry: {...},
properties: {...}
}
const testFeatureNumID = {
type: 'Feature',
id: 2,
geometry: {...},
properties: {...}
}
test('Feature Does not Have an ID', () => {
expect(testFeature).not.toHaveStringID('f2')
expect(testFeature).not.toHaveStringID([1, 'F', 'F12', /SomeID/])
expect(testFeatureNoID).not.toHaveStringID()
expect(testFeatureNumID).not.toHaveStringID()
expect(testFeatureNumID).not.toHaveStringID(2)
})
Parameters:
Name | Type | Attributes | Description |
---|---|---|---|
featureObject |
object | any GeoJSON Feature object | |
SearchID |
string | RegExp | Array.<string> | Array.<RegExp> | <optional> |
Specific value or array of possible values to search for. |