-
Notifications
You must be signed in to change notification settings - Fork 33
/
Copy pathlastfm-base-test.js
78 lines (67 loc) · 2.13 KB
/
lastfm-base-test.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
require('./common');
var LastFmBase = require("../lib/lastfm/lastfm-base");
(function() {
describe("LastFmBase");
it("is an event emitter", function() {
var events = { expected: function(){} };
var gently = new Gently();
var lastfmBase = new LastFmBase();
gently.expect(events, "expected");
lastfmBase.on("test", function() {
events.expected();
});
lastfmBase.emit("test");
});
})();
(function() {
describe("LastFmBase.registerHandlers");
it("attaches events specified in handelers parameter", function() {
var handlers = {
error: function() { },
success: function() { },
anything: function() { }
};
var gently = new Gently();
gently.expect(handlers, "error");
gently.expect(handlers, "success");
gently.expect(handlers, "anything");
var lastfmBase = new LastFmBase();
lastfmBase.registerHandlers(handlers);
lastfmBase.emit("error");
lastfmBase.emit("success");
lastfmBase.emit("anything");
});
})();
(function() {
var lastfmBase, original;
describe("LastFmBase.filterParameters");
before(function() {
lastfmBase = new LastFmBase();
original = { one: 1, two: 2, three: 3 };
});
it("unfiltered object matches original object", function() {
var copy = lastfmBase.filterParameters(original);
assert.deepEqual(copy, original);
});
it("returns copy of original object", function() {
var copy = lastfmBase.filterParameters(original);
copy.four = 4;
assert.notDeepEqual(copy, original);
});
it("filteres out blacklisted parameters", function() {
var copy = lastfmBase.filterParameters(original, ["one", "three"]);
assert.equal(typeof copy.one, "undefined");
assert.equal(typeof copy.three, "undefined");
assert.equal(copy.two, 2);
});
it("automatically removed error, success, handler parameters", function() {
var copy = lastfmBase.filterParameters({
error: emptyFn,
success: emptyFn,
handlers: { }
});
assert.equal(typeof copy.error, "undefined");
assert.equal(typeof copy.success, "undefined");
assert.equal(typeof copy.handlers, "undefined");
});
})();