-
Notifications
You must be signed in to change notification settings - Fork 73
/
Copy pathtest.compass.js
120 lines (99 loc) · 5.11 KB
/
test.compass.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
describe("compass", function () {
var compass = require('cordova/plugin/compass'),
utils = require('cordova/utils'),
exec = require('cordova/exec');
beforeEach(function() {
exec.reset();
});
describe("when getting the current heading", function () {
it("logs an error and doesn't call exec when no success callback given", function () {
spyOn(console, "log");
compass.getCurrentHeading();
expect(console.log).toHaveBeenCalledWith("Compass Error: successCallback is not a function");
expect(exec).not.toHaveBeenCalledWith(jasmine.any(Function), undefined, "Compass", "getHeading", []);
});
it("logs an error and doesn't call exec when success isn't a function", function () {
spyOn(console, "log");
compass.getCurrentHeading(12);
expect(console.log).toHaveBeenCalledWith("Compass Error: successCallback is not a function");
expect(exec).not.toHaveBeenCalledWith(jasmine.any(Function), undefined, "Compass", "getHeading", []);
});
it("logs an error and doesn't call exec when error isn't a function", function () {
var func = function () {};
spyOn(console, "log");
compass.getCurrentHeading(func, 12);
expect(console.log).toHaveBeenCalledWith("Compass Error: errorCallback is not a function");
expect(exec).not.toHaveBeenCalledWith(func, 12, "Compass", "getHeading", []);
});
it("calls exec", function () {
var s = function () {},
f = function () {};
compass.getCurrentHeading(s, f);
expect(exec).toHaveBeenCalledWith(jasmine.any(Function), jasmine.any(Function), "Compass", "getHeading", [undefined]);
});
});
describe("watch heading", function () {
beforeEach(function () {
spyOn(window, "setInterval").andReturn("def");
});
it("logs an error and doesn't call exec when no success callback given", function () {
spyOn(console, "log");
compass.watchHeading();
expect(console.log).toHaveBeenCalledWith("Compass Error: successCallback is not a function");
expect(exec).not.toHaveBeenCalledWith(jasmine.any(Function), undefined, "Compass", "getHeading", []);
});
it("logs an error and doesn't call exec when success isn't a function", function () {
spyOn(console, "log");
compass.watchHeading(12);
expect(console.log).toHaveBeenCalledWith("Compass Error: successCallback is not a function");
expect(exec).not.toHaveBeenCalledWith(jasmine.any(Function), undefined, "Compass", "getHeading", []);
});
it("logs an error and doesn't call exec when error isn't a function", function () {
var func = function () {};
spyOn(console, "log");
compass.watchHeading(func, 12);
expect(console.log).toHaveBeenCalledWith("Compass Error: errorCallback is not a function");
expect(exec).not.toHaveBeenCalledWith(func, 12, "Compass", "getHeading", []);
});
it("generates and returns a uuid for the watch", function () {
spyOn(utils, "createUUID").andReturn(1234);
var result = compass.watchHeading(function () {});
expect(result).toBe(1234);
});
describe("setting the interval", function () {
it("is 100 when not provided", function () {
compass.watchHeading(function () {});
expect(window.setInterval).toHaveBeenCalledWith(jasmine.any(Function), 100);
});
it("is 100 when options provided with no frequency", function () {
compass.watchHeading(function () {}, null, {});
expect(window.setInterval).toHaveBeenCalledWith(jasmine.any(Function), 100);
});
it("is the provided value", function () {
compass.watchHeading(function () {}, null, {frequency: 200});
expect(window.setInterval).toHaveBeenCalledWith(jasmine.any(Function), 200);
});
});
it("gets the compass value for the given interval", function () {
var success = jasmine.createSpy(),
fail = jasmine.createSpy();
compass.watchHeading(success, fail);
//exec the interval callback!
window.setInterval.mostRecentCall.args[0]();
expect(exec).toHaveBeenCalledWith(jasmine.any(Function), jasmine.any(Function), "Compass", "getHeading", [undefined]);
});
});
describe("when clearing the watch", function () {
beforeEach(function () {
spyOn(window, "clearInterval");
});
it("doesn't clear anything if the timer doesn't exist", function () {
compass.clearWatch("Never Gonna Give you Up");
expect(window.clearInterval).not.toHaveBeenCalled();
});
it("can be called with no args", function () {
compass.clearWatch();
expect(window.clearInterval).not.toHaveBeenCalled();
});
});
});