You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
GeoJSON Features have an optional ID member that can be any string or number. This matcher only validates IDs with type string. To check for either number only, use toHaveNumericID. To check for either string or number, use toHaveID.
If a Feature has a commonly used identifier, that identifier SHOULD be included as a member of the Feature object with the name "id", and the value of this member is either a JSON string or number.
An "id" member on a non-feature object gets treated as a foreign member instead of an ID.
This matcher will take an optional argument of either a string, RegExp, or array of any combination of these. If no argument is provided, the matcher will check if the Feature object has an ID member of any value with type string. Otherwise, it will check that the ID member exactly matches either the single input or any of the array values.
Passing a number type to this optional argument will not pass the test, even if the id exactly matches.
Description
GeoJSON Features have an optional ID member that can be any string or number. This matcher only validates IDs with type
string
. To check for eithernumber
only, use toHaveNumericID. To check for eitherstring
ornumber
, use toHaveID.An "id" member on a non-feature object gets treated as a foreign member instead of an ID.
This matcher will take an optional argument of either a
string
,RegExp
, or array of any combination of these. If no argument is provided, the matcher will check if the Feature object has an ID member of any value with typestring
. Otherwise, it will check that the ID member exactly matches either the single input or any of the array values.Passing a
number
type to this optional argument will not pass the test, even if the id exactly matches.Valid GeoJSON Examples
Example Matcher Usage
Passing Tests
String IDs
Input:
'1'
'Test 123'
'Random ID String'
''
Empty Array for Optional Argument
Multiple Array Value Checking for String ID
Only one element passes:
['1', '#719', 'TestID', 'Some String']
['A String ID', /Some/, '2']
[/SomeString/, /123/, /\bString\b/]
More than one element passes:
[/72[0-9]/, /\bString\b/, /71[0-9]/, /Some/, 'Some String']
Failing Tests
Invalid Inputs To Matcher
Rejects each of the following:
undefined
,null
,false
,true
,0
{ someProp: 'I am not GeoJSON', id: 4 }
''
,'Random Feature'
,Otherwise Valid Numeric IDs Fail
Input:
0
-200
200
Infinity
-Infinity
Invalid Inputs To Optional Argument
Rejects when the optional ID to check is
undefined
,null
,false
,true
{ someProp: 'I am not GeoJSON', id: 4 }
{}
NaN
Rejects when ID Does Not Match Optional Input Value
The text was updated successfully, but these errors were encountered: