@@ -21,16 +21,9 @@ describe('QTH locator', () => {
21
21
expect ( BDPair . deg ) . toBeCloseTo ( deg ) ;
22
22
} ;
23
23
24
- const expectInvalifGridErr = ( fn , a , b ) => {
25
- expect . assertions ( 2 ) ;
26
-
27
- try {
28
- fn ( a , b ) ;
29
- } catch ( error ) {
30
- expect ( error ) . toHaveProperty ( 'message' , 'Input is not valid locator string' ) ;
31
- expect ( error ) . toBeInstanceOf ( Error ) ;
32
- }
33
- } ;
24
+ const expectInvalidGridErr = fn => expect ( fn ) . toThrow ( 'Input is not valid locator string' ) ;
25
+
26
+ const expectInvalidLatLngErr = fn => expect ( fn ) . toThrow ( 'Input is not a valid coordinate' ) ;
34
27
35
28
it ( 'Converts locator string to coordinates' , ( ) => {
36
29
expectCoordinates ( qthLocator . locatorToLatLng ( 'KP20le' ) , 60.188 , 24.958 ) ;
@@ -55,18 +48,33 @@ describe('QTH locator', () => {
55
48
} ) ;
56
49
57
50
it ( 'Detect invalid grid' , ( ) => {
58
- expectInvalifGridErr ( qthLocator . locatorToLatLng , 'RZ73' ) ;
51
+ expectInvalidGridErr ( ( ) => qthLocator . locatorToLatLng ( 'RZ73' ) ) ;
59
52
} ) ;
60
53
61
54
it ( 'Locate debatable grid - It is in spec!' , ( ) => {
62
55
expectCoordinates ( qthLocator . locatorToLatLng ( 'RR73' ) , 83.479 , 174.96 ) ;
63
56
} ) ;
64
57
65
58
it ( 'Detect short grid' , ( ) => {
66
- expectInvalifGridErr ( qthLocator . locatorToLatLng , 'R73' ) ;
59
+ expectInvalidGridErr ( ( ) => qthLocator . locatorToLatLng ( 'R73' ) ) ;
67
60
} ) ;
68
61
69
62
it ( 'detect invalid grid in bearingDistance 1' , ( ) => {
70
- expectInvalifGridErr ( qthLocator . bearingDistance , 'FN20qr' , 'F030ll' ) ;
63
+ expectInvalidGridErr ( ( ) => qthLocator . bearingDistance ( 'FN20qr' , 'F030ll' ) ) ;
64
+ } ) ;
65
+
66
+ it ( 'Converts latLng to grid' , ( ) => {
67
+ expect ( qthLocator . latLngToLocator ( 14.3125 , - 32.125 ) ) . toBe ( 'HK34wh' ) ;
68
+ expect ( qthLocator . latLngToLocator ( 60.179 , 24.945 ) ) . toBe ( 'KP20le' ) ;
69
+ expect ( qthLocator . latLngToLocator ( - 33.886048 , 151.193546 ) ) . toBe ( 'QF56oc' ) ;
70
+ expect ( qthLocator . latLngToLocator ( - 22.904788 , - 43.184915 ) ) . toBe ( 'GG87jc' ) ;
71
+ } ) ;
72
+
73
+ it ( 'Throws error for invalid coordinates' , ( ) => {
74
+ expectInvalidLatLngErr ( ( ) => qthLocator . latLngToLocator ( 91 , 120 ) ) ;
75
+ expectInvalidLatLngErr ( ( ) => qthLocator . latLngToLocator ( - 91 , 120 ) ) ;
76
+ expectInvalidLatLngErr ( ( ) => qthLocator . latLngToLocator ( 55 , 181 ) ) ;
77
+ expectInvalidLatLngErr ( ( ) => qthLocator . latLngToLocator ( 55 , - 181 ) ) ;
78
+ expectInvalidLatLngErr ( ( ) => qthLocator . latLngToLocator ( - 91 , - 181 ) ) ;
71
79
} ) ;
72
80
} ) ;
0 commit comments