Last active
December 24, 2015 14:29
-
-
Save cjolly/6812934 to your computer and use it in GitHub Desktop.
How to test javascript geolocation with jasmine
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#= require support/jasmine-given | |
class Geolocation | |
getCurrentPosition: -> | |
options = | |
maximumAge: 0 | |
timeout: 1*10*1000 | |
enableHighAccuracy: true | |
navigator.geolocation.getCurrentPosition(@success, @failure, options) | |
success: (position) => | |
@coordinates = position.coords | |
failure: (error) => | |
@coordinates = null | |
describe "Geolocation", -> | |
Given -> @subject = new Geolocation() | |
Given -> @spy = spyOn(navigator.geolocation, 'getCurrentPosition') | |
When -> @subject.getCurrentPosition() | |
describe "#getCurrentPosition", -> | |
describe "success", -> | |
Given -> @spy.andCallFake(-> arguments[0](coords: { latitude: 1, longitude: 2 })) | |
Then -> expect(@subject.coordinates).toEqual({latitude: 1, longitude: 2}) | |
describe "failure", -> | |
Given -> @spy.andCallFake(-> arguments[1]({error: "FAILED"})) | |
Then -> @subject.coordinates is null |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment