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
startLocationUpdatesAsync();
// $ExpectError: first argument mush be a string
startLocationUpdatesAsync(1337);
// $ExpectError: second argument must be an object
startLocationUpdatesAsync('taskName', 69);
startLocationUpdatesAsync('taskName', {
// $ExpectError: invalid accuracy
accuracy: 1,
// $ExpectError: invalid activityType
activityType: 1,
// $ExpectError: `notificationTitle` is required props
foregroundService: { notificationBody: 'str' },
});
});
});
it('should raise an error when call function with invalid arguments', () => {
// $ExpectError: first argument is required
startLocationUpdatesAsync();
// $ExpectError: first argument mush be a string
startLocationUpdatesAsync(1337);
// $ExpectError: second argument must be an object
startLocationUpdatesAsync('taskName', 69);
startLocationUpdatesAsync('taskName', {
// $ExpectError: invalid accuracy
accuracy: 1,
// $ExpectError: invalid activityType
activityType: 1,
// $ExpectError: `notificationTitle` is required props
foregroundService: { notificationBody: 'str' },
});
});
});
it('should raise an error when call function with invalid arguments', () => {
// $ExpectError: first argument is required
startLocationUpdatesAsync();
// $ExpectError: first argument mush be a string
startLocationUpdatesAsync(1337);
// $ExpectError: second argument must be an object
startLocationUpdatesAsync('taskName', 69);
startLocationUpdatesAsync('taskName', {
// $ExpectError: invalid accuracy
accuracy: 1,
// $ExpectError: invalid activityType
activityType: 1,
// $ExpectError: `notificationTitle` is required props
foregroundService: { notificationBody: 'str' },
});
});
});
startLocationUpdatesAsync('taskName', {
foregroundService: {
notificationTitle: 'str',
notificationBody: 'str',
},
});
startLocationUpdatesAsync('taskName', {
foregroundService: {
notificationTitle: 'str',
notificationBody: 'str',
notificationColor: 'red',
},
});
startLocationUpdatesAsync('taskName').then(result => {
(result: void);
// $ExpectError: check any
(result: string);
});
});
async startLocationUpdates(accuracy = this.state.accuracy) {
await Location.startLocationUpdatesAsync(LOCATION_UPDATES_TASK, {
accuracy,
activityType: this.state.activityType,
pausesUpdatesAutomatically: this.state.activityType != null,
showsBackgroundLocationIndicator: this.state.showsBackgroundLocationIndicator,
deferredUpdatesInterval: 60 * 1000, // 1 minute
deferredUpdatesDistance: 100, // 100 meters
foregroundService: {
notificationTitle: 'expo-location-demo',
notificationBody: 'Background location is running...',
notificationColor: Colors.tintColor,
},
});
if (!this.state.isTracking) {
alert(
// tslint:disable-next-line max-line-length
async startLocationUpdates(accuracy = this.state.accuracy) {
await Location.startLocationUpdatesAsync(LOCATION_UPDATES_TASK, {
accuracy,
showsBackgroundLocationIndicator: this.state.showsBackgroundLocationIndicator,
});
if (!this.state.isTracking) {
alert(
'Now you can send app to the background, go somewhere and come back here! You can even terminate the app and it will be woken up when the new significant location change comes out.'
);
}
this.setState({ isTracking: true });
}