Skip to content

Commit

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

Resolves: #37
  • Loading branch information
M-Scott-Lassiter committed Jun 8, 2022
1 parent 4636be6 commit cefddd6
Show file tree
Hide file tree
Showing 61 changed files with 1,158 additions and 5 deletions.
3 changes: 2 additions & 1 deletion .cz-config.js
Expand Up @@ -18,7 +18,8 @@ const allMatchers = [
{ name: 'toBePointGeometry' },
{ name: 'toBePolygonGeometry' },
{ name: 'toBeValidGeoJSON' },
{ name: 'toHaveID' }
{ name: 'toHaveID' },
{ name: 'toHaveStringID' }
]

const documentationScopes = [
Expand Down
2 changes: 1 addition & 1 deletion README.md
Expand Up @@ -157,12 +157,12 @@ _Future_

- [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)
- [toHaveStringID](https://m-scott-lassiter.github.io/jest-geojson/Matchers.Features.html#.toHaveStringID)

---

_Future_

- [ ] toHaveStringID
- [ ] toHaveNumericID
- [ ] toHaveProperties (array of [property, optional values])

Expand Down
3 changes: 3 additions & 0 deletions docs/Core.BoundingBoxes.html
Expand Up @@ -224,6 +224,9 @@ <h3>Namespaces</h3>
<li data-type="method">
<a href="Matchers.Features.html#.toHaveID">toHaveID</a>
</li>
<li data-type="method">
<a href="Matchers.Features.html#.toHaveStringID">toHaveStringID</a>
</li>
</ul>
</li>
<li>
Expand Down
3 changes: 3 additions & 0 deletions docs/Core.Coordinates.html
Expand Up @@ -224,6 +224,9 @@ <h3>Namespaces</h3>
<li data-type="method">
<a href="Matchers.Features.html#.toHaveID">toHaveID</a>
</li>
<li data-type="method">
<a href="Matchers.Features.html#.toHaveStringID">toHaveStringID</a>
</li>
</ul>
</li>
<li>
Expand Down
3 changes: 3 additions & 0 deletions docs/Core.FeatureCollections.html
Expand Up @@ -224,6 +224,9 @@ <h3>Namespaces</h3>
<li data-type="method">
<a href="Matchers.Features.html#.toHaveID">toHaveID</a>
</li>
<li data-type="method">
<a href="Matchers.Features.html#.toHaveStringID">toHaveStringID</a>
</li>
</ul>
</li>
<li>
Expand Down
3 changes: 3 additions & 0 deletions docs/Core.Features.html
Expand Up @@ -224,6 +224,9 @@ <h3>Namespaces</h3>
<li data-type="method">
<a href="Matchers.Features.html#.toHaveID">toHaveID</a>
</li>
<li data-type="method">
<a href="Matchers.Features.html#.toHaveStringID">toHaveStringID</a>
</li>
</ul>
</li>
<li>
Expand Down
3 changes: 3 additions & 0 deletions docs/Core.Geometries.html
Expand Up @@ -224,6 +224,9 @@ <h3>Namespaces</h3>
<li data-type="method">
<a href="Matchers.Features.html#.toHaveID">toHaveID</a>
</li>
<li data-type="method">
<a href="Matchers.Features.html#.toHaveStringID">toHaveStringID</a>
</li>
</ul>
</li>
<li>
Expand Down
3 changes: 3 additions & 0 deletions docs/Core.Utilities.html
Expand Up @@ -224,6 +224,9 @@ <h3>Namespaces</h3>
<li data-type="method">
<a href="Matchers.Features.html#.toHaveID">toHaveID</a>
</li>
<li data-type="method">
<a href="Matchers.Features.html#.toHaveStringID">toHaveStringID</a>
</li>
</ul>
</li>
<li>
Expand Down
3 changes: 3 additions & 0 deletions docs/Core.html
Expand Up @@ -224,6 +224,9 @@ <h3>Namespaces</h3>
<li data-type="method">
<a href="Matchers.Features.html#.toHaveID">toHaveID</a>
</li>
<li data-type="method">
<a href="Matchers.Features.html#.toHaveStringID">toHaveStringID</a>
</li>
</ul>
</li>
<li>
Expand Down
3 changes: 3 additions & 0 deletions docs/Matchers.BoundingBoxes.html
Expand Up @@ -224,6 +224,9 @@ <h3>Namespaces</h3>
<li data-type="method">
<a href="Matchers.Features.html#.toHaveID">toHaveID</a>
</li>
<li data-type="method">
<a href="Matchers.Features.html#.toHaveStringID">toHaveStringID</a>
</li>
</ul>
</li>
<li>
Expand Down
3 changes: 3 additions & 0 deletions docs/Matchers.Coordinates.html
Expand Up @@ -224,6 +224,9 @@ <h3>Namespaces</h3>
<li data-type="method">
<a href="Matchers.Features.html#.toHaveID">toHaveID</a>
</li>
<li data-type="method">
<a href="Matchers.Features.html#.toHaveStringID">toHaveStringID</a>
</li>
</ul>
</li>
<li>
Expand Down
3 changes: 3 additions & 0 deletions docs/Matchers.FeatureCollections.html
Expand Up @@ -224,6 +224,9 @@ <h3>Namespaces</h3>
<li data-type="method">
<a href="Matchers.Features.html#.toHaveID">toHaveID</a>
</li>
<li data-type="method">
<a href="Matchers.Features.html#.toHaveStringID">toHaveStringID</a>
</li>
</ul>
</li>
<li>
Expand Down
142 changes: 142 additions & 0 deletions docs/Matchers.Features.html
Expand Up @@ -224,6 +224,9 @@ <h3>Namespaces</h3>
<li data-type="method">
<a href="Matchers.Features.html#.toHaveID">toHaveID</a>
</li>
<li data-type="method">
<a href="Matchers.Features.html#.toHaveStringID">toHaveStringID</a>
</li>
</ul>
</li>
<li>
Expand Down Expand Up @@ -584,6 +587,145 @@ <h5>Parameters:</h5>
</tr>
</tbody>
</table>

<h4 class="name" id=".toHaveStringID">
<span class="type-signature">(static) </span>toHaveStringID<span
class="signature"
>(featureObject, SearchID<span class="signature-attributes">opt</span
>)</span
><span class="type-signature"></span>
</h4>

<dl class="details">
<dt class="tag-source">Source:</dt>
<dd class="tag-source">
<ul class="dummy">
<li>
<a href="matchers_features_toHaveStringID.js.html"
>matchers/features/toHaveStringID.js</a
>,
<a href="matchers_features_toHaveStringID.js.html#line57"
>line 57</a
>
</li>
</ul>
</dd>

<dt class="tag-see">See:</dt>
<dd class="tag-see">
<ul>
<li>
<a
href="https://github.com/M-Scott-Lassiter/jest-geojson/issues/37"
>https://github.com/M-Scott-Lassiter/jest-geojson/issues/37</a
>
</li>
</ul>
</dd>
</dl>

<div class="description usertext">
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.
</div>

<h5>Examples</h5>

<pre class="prettyprint"><code>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]+/])

expect(testFeature).not.toHaveStringID('f2')
expect(testFeature).not.toHaveStringID([1, 'F', 'F12', /SomeID/])
})</code></pre>

<pre class="prettyprint"><code>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)
})</code></pre>

<h5>Parameters:</h5>

<table class="params">
<thead>
<tr>
<th>Name</th>

<th>Type</th>

<th>Attributes</th>

<th class="last">Description</th>
</tr>
</thead>

<tbody>
<tr>
<td class="name"><code>featureObject</code></td>

<td class="type">
<span class="param-type">object</span>
</td>

<td class="attributes"></td>

<td class="description last">any GeoJSON Feature object</td>
</tr>

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

<td class="type">
<span class="param-type">string</span>
|

<span class="param-type">RegExp</span>
|

<span class="param-type">Array.&lt;string></span>
|

<span class="param-type">Array.&lt;RegExp></span>
</td>

<td class="attributes">&lt;optional><br /></td>

<td class="description last">
Specific value or array of possible values to search for.
</td>
</tr>
</tbody>
</table>
</article>
</section>
</div>
Expand Down
3 changes: 3 additions & 0 deletions docs/Matchers.Functional.html
Expand Up @@ -224,6 +224,9 @@ <h3>Namespaces</h3>
<li data-type="method">
<a href="Matchers.Features.html#.toHaveID">toHaveID</a>
</li>
<li data-type="method">
<a href="Matchers.Features.html#.toHaveStringID">toHaveStringID</a>
</li>
</ul>
</li>
<li>
Expand Down
3 changes: 3 additions & 0 deletions docs/Matchers.Geometries.html
Expand Up @@ -224,6 +224,9 @@ <h3>Namespaces</h3>
<li data-type="method">
<a href="Matchers.Features.html#.toHaveID">toHaveID</a>
</li>
<li data-type="method">
<a href="Matchers.Features.html#.toHaveStringID">toHaveStringID</a>
</li>
</ul>
</li>
<li>
Expand Down
3 changes: 3 additions & 0 deletions docs/Matchers.html
Expand Up @@ -224,6 +224,9 @@ <h3>Namespaces</h3>
<li data-type="method">
<a href="Matchers.Features.html#.toHaveID">toHaveID</a>
</li>
<li data-type="method">
<a href="Matchers.Features.html#.toHaveStringID">toHaveStringID</a>
</li>
</ul>
</li>
<li>
Expand Down
3 changes: 3 additions & 0 deletions docs/core_boundingBoxes_valid2DBoundingBox.js.html
Expand Up @@ -224,6 +224,9 @@ <h3>Namespaces</h3>
<li data-type="method">
<a href="Matchers.Features.html#.toHaveID">toHaveID</a>
</li>
<li data-type="method">
<a href="Matchers.Features.html#.toHaveStringID">toHaveStringID</a>
</li>
</ul>
</li>
<li>
Expand Down
3 changes: 3 additions & 0 deletions docs/core_boundingBoxes_valid3DBoundingBox.js.html
Expand Up @@ -224,6 +224,9 @@ <h3>Namespaces</h3>
<li data-type="method">
<a href="Matchers.Features.html#.toHaveID">toHaveID</a>
</li>
<li data-type="method">
<a href="Matchers.Features.html#.toHaveStringID">toHaveStringID</a>
</li>
</ul>
</li>
<li>
Expand Down
3 changes: 3 additions & 0 deletions docs/core_boundingBoxes_validBoundingBox.js.html
Expand Up @@ -224,6 +224,9 @@ <h3>Namespaces</h3>
<li data-type="method">
<a href="Matchers.Features.html#.toHaveID">toHaveID</a>
</li>
<li data-type="method">
<a href="Matchers.Features.html#.toHaveStringID">toHaveStringID</a>
</li>
</ul>
</li>
<li>
Expand Down
3 changes: 3 additions & 0 deletions docs/core_coordinates_valid2DCoordinate.js.html
Expand Up @@ -224,6 +224,9 @@ <h3>Namespaces</h3>
<li data-type="method">
<a href="Matchers.Features.html#.toHaveID">toHaveID</a>
</li>
<li data-type="method">
<a href="Matchers.Features.html#.toHaveStringID">toHaveStringID</a>
</li>
</ul>
</li>
<li>
Expand Down
3 changes: 3 additions & 0 deletions docs/core_coordinates_valid3DCoordinate.js.html
Expand Up @@ -224,6 +224,9 @@ <h3>Namespaces</h3>
<li data-type="method">
<a href="Matchers.Features.html#.toHaveID">toHaveID</a>
</li>
<li data-type="method">
<a href="Matchers.Features.html#.toHaveStringID">toHaveStringID</a>
</li>
</ul>
</li>
<li>
Expand Down
3 changes: 3 additions & 0 deletions docs/core_coordinates_validCoordinate.js.html
Expand Up @@ -224,6 +224,9 @@ <h3>Namespaces</h3>
<li data-type="method">
<a href="Matchers.Features.html#.toHaveID">toHaveID</a>
</li>
<li data-type="method">
<a href="Matchers.Features.html#.toHaveStringID">toHaveStringID</a>
</li>
</ul>
</li>
<li>
Expand Down
3 changes: 3 additions & 0 deletions docs/core_featureCollections_featureCollection.js.html
Expand Up @@ -224,6 +224,9 @@ <h3>Namespaces</h3>
<li data-type="method">
<a href="Matchers.Features.html#.toHaveID">toHaveID</a>
</li>
<li data-type="method">
<a href="Matchers.Features.html#.toHaveStringID">toHaveStringID</a>
</li>
</ul>
</li>
<li>
Expand Down
3 changes: 3 additions & 0 deletions docs/core_features_feature.js.html
Expand Up @@ -224,6 +224,9 @@ <h3>Namespaces</h3>
<li data-type="method">
<a href="Matchers.Features.html#.toHaveID">toHaveID</a>
</li>
<li data-type="method">
<a href="Matchers.Features.html#.toHaveStringID">toHaveStringID</a>
</li>
</ul>
</li>
<li>
Expand Down
3 changes: 3 additions & 0 deletions docs/core_features_hasID.js.html
Expand Up @@ -224,6 +224,9 @@ <h3>Namespaces</h3>
<li data-type="method">
<a href="Matchers.Features.html#.toHaveID">toHaveID</a>
</li>
<li data-type="method">
<a href="Matchers.Features.html#.toHaveStringID">toHaveStringID</a>
</li>
</ul>
</li>
<li>
Expand Down

0 comments on commit cefddd6

Please sign in to comment.