Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
it('should raise an error when call function with invalid arguments', () => {
// $ExpectError: first argument is required
startGeofencingAsync();
// $ExpectError: first argument mush be a string
startGeofencingAsync(1337);
startGeofencingAsync('taskName', [
// $ExpectError: must be a region object
69,
]);
startGeofencingAsync('taskName', [
{
latitude: 14,
longitude: 48,
// $ExpectError: must be a number
radius: '69',
},
]);
startGeofencingAsync('taskName', [
radius: 69,
},
]);
startGeofencingAsync('taskName', [
{
latitude: 14,
longitude: 48,
radius: 69,
identifier: 'id',
notifyOnEnter: false,
notifyOnExit: false,
},
]);
startGeofencingAsync('taskName').then(result => {
(result: void);
// $ExpectError: check any
(result: string);
});
});
startGeofencingAsync('taskName', [
// $ExpectError: must be a region object
69,
]);
startGeofencingAsync('taskName', [
{
latitude: 14,
longitude: 48,
// $ExpectError: must be a number
radius: '69',
},
]);
startGeofencingAsync('taskName', [
// $ExpectError: `abc` prop is missing in Region
{
latitude: 14,
longitude: 48,
radius: 666,
abc: 11,
},
]);
});
});
async () => {
if (await Location.hasStartedGeofencingAsync(GEOFENCING_TASK)) {
// update existing geofencing task
await Location.startGeofencingAsync(GEOFENCING_TASK, this.state.geofencingRegions);
}
}
);
onMapPress = async ({ nativeEvent: { coordinate } }: MapEvent) => {
const geofencingRegions = [...this.state.geofencingRegions];
geofencingRegions.push({
identifier: `${coordinate.latitude},${coordinate.longitude}`,
latitude: coordinate.latitude,
longitude: coordinate.longitude,
radius: 50,
});
this.setState({ geofencingRegions });
if (await Location.hasStartedGeofencingAsync(GEOFENCING_TASK)) {
// update existing geofencing task
await Location.startGeofencingAsync(GEOFENCING_TASK, geofencingRegions);
}
}
toggleGeofencing = async () => {
if (this.state.isGeofencing) {
await Location.stopGeofencingAsync(GEOFENCING_TASK);
this.setState({ geofencingRegions: [] });
} else {
await Location.startGeofencingAsync(GEOFENCING_TASK, this.state.geofencingRegions);
}
this.setState({ isGeofencing: !this.state.isGeofencing });
}