This repository was archived by the owner on Mar 10, 2020. It is now read-only.
-
-
Notifications
You must be signed in to change notification settings - Fork 121
/
Copy pathutil_spec.js
55 lines (47 loc) · 1.58 KB
/
util_spec.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
var util = ascoltatori.util;
describe("ascoltatori.util", function() {
it("should respond to alias", function() {
expect(util).to.respondTo("alias");
});
it("should create copy a function into another", function() {
var obj = {
meth: function() {}
};
util.alias(obj, "meth", "methB");
expect(obj.methB).to.eql(obj.meth);
});
it("should return the object when aliasing", function() {
var obj = {
meth: function() {}
};
expect(util.alias(obj, "meth", "methB")).to.eql(obj);
});
it("should raise an exception if we try to alias something that's not a function", function() {
var obj = {
a: function() {}
};
expect(function() {
util.alias({}, "a", "c");
}).to.throw ("'a' is not a function");
});
describe("aliasAscoltatore", function() {
it("should alias all pub/sub method for each ascoltatore", function() {
var obj = {};
var mock = sinon.mock(util);
mock.expects("alias").withArgs(obj, "publish", "pub").once();
mock.expects("alias").withArgs(obj, "subscribe", "sub").once();
mock.expects("alias").withArgs(obj, "unsubscribe", "unsub").once();
util.aliasAscoltatore(obj);
mock.verify();
});
it("should alias all pub/sub method for each ascoltatore", function() {
var obj = {};
var stub = sinon.stub(util, "alias");
expect(util.aliasAscoltatore(obj)).to.equal(obj);
stub.restore();
});
});
it("should build two different unique identifiers", function() {
expect(util.buildIdentifier()).not.to.be.eql(util.buildIdentifier());
});
});