1
var suite = new Y.Test.Suite("AOP");
3
suite.add(new Y.Test.Case({
8
//"test before/after with falsy context binds args": "ticket pending"
11
// Trac ticket noted as value
12
"test originalRetVal not overwritten by nested call": 2530030
16
"test before/after with falsy context binds args": function () {
17
//Y.Do.before(fn, obj, "method", null, "a", obj, null);
20
"test Y.AlterReturn": function() {
21
var et = new Y.EventTarget(), count = 0;
25
Y.Assert.isTrue(Y.Do.originalRetVal);
26
Y.Assert.isTrue(Y.Do.currentRetVal);
27
return new Y.Do.AlterReturn("altered return", "altered");
32
Y.Assert.isTrue(Y.Do.originalRetVal);
33
Y.Assert.areEqual("altered", Y.Do.currentRetVal);
38
Y.Assert.areEqual(2, count);
42
"test originalRetVal not overwritten by nested call": function () {
54
Y.Do.after(function () {
55
return Y.Do.originalRetVal.toLowerCase();
58
Y.Do.after(function () {
59
// It doesn't matter what happens here, but for example, we
60
// don't interfere with the return value
63
Y.Assert.areSame('a', obj.a());
67
suite.add(new Y.Test.Case({
68
name: "EventTarget on/before/after",
70
"test target.on(fn, host, methodName)": function () {
71
var target = new Y.EventTarget(),
76
Y.Do.before = function () {
77
called.push("before");
78
return before.apply(this, arguments);
82
called.push("callback");
86
called.push("method");
89
target.method = method;
91
// awkward that you have to pass the target, and even more so
92
// because this means every EventTarget is effectively an alias
94
handle = target.on(callback, target, "method");
96
Y.Assert.areNotSame(method, target.method);
97
Y.Assert.isObject(handle);
98
Y.Assert.isInstanceOf(Y.Do.Method, handle.evt);
102
Y.ArrayAssert.itemsAreSame(["before", "callback", "method"], called);
104
// restore the method for other tests
105
Y.Do.before = before;
108
"test target.on(fn, host, methodName, context)": function () {
109
var target = new Y.EventTarget(),
113
before = Y.Do.before;
114
Y.Do.before = function () {
115
called.push("before");
116
return before.apply(this, arguments);
119
function callback() {
120
called.push("callback");
124
called.push("method");
127
target.method = method;
129
// awkward that you have to pass the target, and even more so
130
// because this means every EventTarget is effectively an alias
132
handle = target.on(callback, target, "method");
134
Y.Assert.areNotSame(method, target.method);
135
Y.Assert.isObject(handle);
136
Y.Assert.isInstanceOf(Y.Do.Method, handle.evt);
140
Y.ArrayAssert.itemsAreSame(["before", "callback", "method"], called);
142
// restore the method for other tests
143
Y.Do.before = before;
146
"test target.on(fn, host, noSuchMethod)": function () {
149
"test target.on([fnA, fnB, fnC], host, noSuchMethod)": function () {
152
"test target.before() is an alias for target.on()": function () {
156
suite.add(new Y.Test.Case({
157
name: "return Y.Do.Classes to affect fn flow"
159
// Test each in before and after phases
166
Y.Test.Runner.add(suite);