Administrator
2022-09-14 58d006e05dcf2a20d0ec5367dd03d66a61db6849
提交 | 用户 | 时间
58d006 1 describe("Creating a marker", function() {
A 2   var map, marker;
3
4   beforeEach(function() {
5     map = map || new GMaps({
6       el : '#map-with-markers',
7       lat : -12.0533,
8       lng: -77.0293,
9       zoom: 14
10     });
11   });
12
13   describe("With basic options", function() {
14     beforeEach(function() {
15       marker = map.addMarker({
16         lat : -12.0533,
17         lng: -77.0293,
18         title : 'New marker'
19       });
20     });
21
22     it("should add the marker to the markers collection", function() {
23       expect(map.markers.length).toEqual(1);
24       expect(map.markers[0]).toEqual(marker);
25     });
26
27     it("should create a marker with defined position", function() {
28       // Fix for floating-point bug
29       expect(parseFloat(marker.getPosition().lat().toFixed(4))).toEqual(-12.0533);
30       expect(parseFloat(marker.getPosition().lng().toFixed(4))).toEqual(-77.0293);
31     });
32   });
33
34   describe("With events", function() {
35     var callbacks;
36
37     beforeEach(function() {
38       callbacks = {
39         onclick : function() {
40           console.log(this.title);
41         }
42       };
43
44       spyOn(callbacks, 'onclick').andCallThrough();
45
46       marker = map.addMarker({
47         lat : -12.0533,
48         lng: -77.0193,
49         title : 'New marker',
50         click : callbacks.onclick
51       });
52     });
53
54     it("should respond to click event", function() {
55       google.maps.event.trigger(marker, 'click');
56
57       expect(callbacks.onclick).toHaveBeenCalled();
58     });
59   });
60 });