Skip to content

Instantly share code, notes, and snippets.

@zspencer
Created May 20, 2011 11:06
Show Gist options
  • Save zspencer/982732 to your computer and use it in GitHub Desktop.
Save zspencer/982732 to your computer and use it in GitHub Desktop.
Screwy way to stub instantiation of a class in js
describe("PlacerOfNeed", function() {
var placer;
beforeEach(function() {
placer = new ForChange.PlacerOfNeed();
});
describe("Creating the marker", function() {
beforeEach(function() {
spyOn(google.maps, 'Marker')
});
it("Creates a google marker with the LatLng it created", function() {
google.maps.LatLng.prototype = { woah: 'man!' }
placer.place({need: {latitude: 25, longitude: 25}});
expect(google.maps.Marker).toHaveBeenCalledWith({position: { woah : "man!" }, map: undefined});
google.maps.LatLng.prototype = {}
});
});
});
var ForChange = {};
ForChange.PlacerOfNeed = function() {};
ForChange.PlacerOfNeed.prototype = {
place: function(options) {
var coordinates = new google.maps.LatLng(options.need.latitude, options.need.longitude);
new google.maps.Marker({position: coordinates , map: options.map});
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment