-
Notifications
You must be signed in to change notification settings - Fork 0
/
toBeMultiLineStringGeometry.js
83 lines (77 loc) · 2.85 KB
/
toBeMultiLineStringGeometry.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
const { multiLineStringGeometry } = require('../../core/geometries/multiLineStringGeometry')
// eslint-disable-next-line jsdoc/require-returns
/**
* Verifies an object is a valid GeoJSON MultiLineString Geometry. This geometry requires a
* 'type' property that must equal "MultiLineString", and a 'coordinates' property that contains
* an array of linestring arrays (i.e. each linestring array containing at least two or more valid
* WGS-84 GeoJSON coordinates).
*
* The coordinates may be an empty array, but may not be an array of empty arrays.
*
* Foreign members are allowed with the exception of 'geometry', 'properties', or 'features'.
*
* @memberof Matchers.Geometries
* @see https://github.com/M-Scott-Lassiter/jest-geojson/issues/12
* @param {object} geometryObject a GeoJSON MultiLineString Geometry object
* @example
const multiLineString = {
"type": "MultiLineString",
"coordinates": [
[
[100.0, 0.0],
[101.0, 1.0]
],
[
[102.0, 2.0],
[103.0, 3.0]
]
]
}
const multiLineStringOneCoordinate = {
"type": "MultiLineString",
"coordinates": [
[
[100.0, 0.0]
]
]
}
const point = {
type: "Point",
coordinates: [100.0, 0.0]
}
expect(multiLineString).toBeMultiLineStringGeometry()
expect(point).not.toBeMultiLineStringGeometry()
expect(multiLineStringOneCoordinate).not.toBeMultiLineStringGeometry()
*/
function toBeMultiLineStringGeometry(geometryObject) {
const { printReceived, matcherHint } = this.utils
const passMessage =
// eslint-disable-next-line prefer-template
matcherHint('.not.toBeMultiLineStringGeometry', 'GeometryObject', '') +
'\n\n' +
`Expected input to not be a valid GeoJSON MultiLineString geometry.\n\n` +
`Received: ${printReceived(geometryObject)}`
/**
* Combines a custom error message with built in Jest tools to provide a more descriptive error
* meessage to the end user.
*
* @param {string} errorMessage Error message text to return to the user
* @returns {string} Concatenated Jest test result string
*/
function failMessage(errorMessage) {
return (
// eslint-disable-next-line prefer-template, no-unused-expressions
matcherHint('.toBeMultiLineStringGeometry', 'GeometryObject', '') +
'\n\n' +
`${errorMessage}\n\n` +
`Received: ${printReceived(geometryObject)}`
)
}
try {
multiLineStringGeometry(geometryObject)
} catch (err) {
return { pass: false, message: () => failMessage(err.message) }
}
return { pass: true, message: () => passMessage }
}
exports.toBeMultiLineStringGeometry = toBeMultiLineStringGeometry