Skip to content

Commit

Permalink
feat(toHaveID): add new matcher
Browse files Browse the repository at this point in the history
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.

Resolves: #36
  • Loading branch information
M-Scott-Lassiter committed Jun 7, 2022
1 parent ea16aa1 commit 5bae7f0
Show file tree
Hide file tree
Showing 16 changed files with 1,361 additions and 34 deletions.
3 changes: 2 additions & 1 deletion .cz-config.js
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,8 @@ const allMatchers = [
{ name: 'toBeMultiPolygonGeometry' },
{ name: 'toBePointGeometry' },
{ name: 'toBePolygonGeometry' },
{ name: 'toBeValidGeoJSON' }
{ name: 'toBeValidGeoJSON' },
{ name: 'toHaveID' }
]

const documentationScopes = [
Expand Down
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -156,12 +156,12 @@ _Future_
## Features

- [toBeFeature](https://m-scott-lassiter.github.io/jest-geojson/Matchers.Features.html#.toBeFeature)
- [toHaveID](https://m-scott-lassiter.github.io/jest-geojson/Matchers.Features.html#.toHaveID)

---

_Future_

- [ ] toHaveID
- [ ] toHaveStringID
- [ ] toHaveNumericID
- [ ] toHaveProperties (array of [property, optional values])
Expand Down
35 changes: 28 additions & 7 deletions docs/Core.Features.html
Original file line number Diff line number Diff line change
Expand Up @@ -558,7 +558,7 @@ <h5>Returns:</h5>

<h4 class="name" id=".hasID">
<span class="type-signature">(static) </span>hasID<span class="signature"
>(featureObject, searchID<span class="signature-attributes">opt</span
>(featureObject, SearchID<span class="signature-attributes">opt</span
>)</span
><span class="type-signature"> &rarr; {boolean}</span>
</h4>
Expand All @@ -569,7 +569,7 @@ <h4 class="name" id=".hasID">
<ul class="dummy">
<li>
<a href="core_features_hasID.js.html">core/features/hasID.js</a
>, <a href="core_features_hasID.js.html#line42">line 42</a>
>, <a href="core_features_hasID.js.html#line43">line 43</a>
</li>
</ul>
</dd>
Expand All @@ -588,7 +588,7 @@ <h4 class="name" id=".hasID">
</dl>

<div class="description usertext">
Checks if a GeoJSON Feature has an ID. Providing an optional searchID
Checks if a GeoJSON Feature has an ID. Providing an optional SearchID
argument will check for that exact ID or array of possible ID values.
</div>

Expand Down Expand Up @@ -647,7 +647,7 @@ <h5>Parameters:</h5>
</tr>

<tr>
<td class="name"><code>searchID</code></td>
<td class="name"><code>SearchID</code></td>

<td class="type">
<span class="param-type">string</span>
Expand Down Expand Up @@ -703,7 +703,27 @@ <h5>Throws:</h5>
<dl>
<dt>
<div class="param-desc usertext">
Optional searchID must be either a number, string, RegExp,
Feature object must have an "id" member
</div>
</dt>
<dd></dd>
<dt>
<dl class="param-type">
<dt>Type</dt>
<dd>
<span class="param-type">Error</span>
</dd>
</dl>
</dt>
<dd></dd>
</dl>
</li>

<li>
<dl>
<dt>
<div class="param-desc usertext">
Optional SearchID must be either a number, string, RegExp,
or array of any of these values
</div>
</dt>
Expand All @@ -726,8 +746,9 @@ <h5>Returns:</h5>
<div class="param-desc">
True 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 acceptable input types. Returns
false otherwise.
provided), or any value within an array of any combination of strings,
numbers, or RegExp. If the object has an ID that does not match SearchID, it
returns false.
</div>

<dl class="param-type">
Expand Down
11 changes: 8 additions & 3 deletions docs/Matchers.Features.html
Original file line number Diff line number Diff line change
Expand Up @@ -469,7 +469,7 @@ <h4 class="name" id=".toHaveID">
<a href="matchers_features_toHaveID.js.html"
>matchers/features/toHaveID.js</a
>,
<a href="matchers_features_toHaveID.js.html#line41">line 41</a>
<a href="matchers_features_toHaveID.js.html#line45">line 45</a>
</li>
</ul>
</dd>
Expand All @@ -488,8 +488,12 @@ <h4 class="name" id=".toHaveID">
</dl>

<div class="description usertext">
Checks if a GeoJSON Feature has an ID. Providing an optional searchID
argument will check for that exact ID or array of possible ID values.
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.
</div>

<h5>Examples</h5>
Expand All @@ -503,6 +507,7 @@ <h5>Examples</h5>

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]+/])

Expand Down
Loading

0 comments on commit 5bae7f0

Please sign in to comment.