This repository was archived by the owner on Nov 27, 2018. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 9
/
Copy pathobserver.js
71 lines (65 loc) · 2.22 KB
/
observer.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
var $ = require("../lib/abaaso.js"),
sample = {};
sample.obj = {id: "test"};
sample.event = "custom";
sample.fn = function () { void(0); };
sample.id = "handler";
sample.scope = sample.obj;
sample.state = "all";
exports["on"] = {
setUp: function (done) {
done();
},
direct: function (test) {
test.expect(3);
test.throws(function () { $.on(sample.obj, undefined, sample.fn, sample.id, sample.scope, sample.state); }, Error, "Event is undefined");
test.throws(function () { $.on(sample.obj, sample.event, undefined, sample.id, sample.scope, sample.state); }, Error, "Handler is not a function");
test.equal($.on(sample.obj, sample.event, sample.fn, sample.id, sample.scope, sample.state), sample.obj, "Should match");
test.done();
}
};
exports["list"] = {
setUp: function (done) {
done();
},
direct: function (test) {
test.expect(2);
test.equal($.listeners("invalid", sample.event).hasOwnProperty(sample.state), false, "Should be false");
test.equal($.listeners(sample.obj, sample.event).hasOwnProperty(sample.state), true, "Should be true");
test.done();
}
};
exports["fire"] = {
setUp: function (done) {
done();
},
direct: function (test) {
test.expect(1);
test.equal($.fire(sample.obj, sample.event), sample.obj, "Should match");
test.done();
}
};
exports["un"] = {
setUp: function (done) {
done();
},
direct: function (test) {
test.expect(1);
test.equal($.un(sample.obj, sample.event, sample.id, sample.state), sample.obj, "Should match");
test.done();
}
};
exports["once"] = {
setUp: function (done) {
done();
},
direct: function (test) {
test.expect(5);
test.throws(function () { $.once(sample.obj, undefined, sample.fn, sample.id, sample.scope, sample.state); }, Error, "Event is undefined");
test.throws(function () { $.once(sample.obj, sample.event, undefined, sample.id, sample.scope, sample.state); }, Error, "Handler is not a function");
test.equal($.once(sample.obj, sample.event, sample.fn, sample.id, sample.scope, sample.state), sample.obj, "Should match");
test.equal($.fire(sample.obj, sample.event), sample.obj, "Should match");
test.equal($.listeners(sample.obj, sample.event)[sample.state].hasOwnProperty(sample.id), false, "Should be false");
test.done();
}
};