1 // ========================================================================== 2 // SC.Statechart Unit Test 3 // ========================================================================== 4 /*globals SC */ 5 6 var Obj, obj, async, func; 7 8 // .......................................................... 9 // CONTENT CHANGING 10 // 11 12 module("SC.Async Tests", { 13 setup: function() { 14 Obj = SC.Object.extend({ 15 fooInvoked: NO, 16 arg1: null, 17 arg2: null, 18 19 foo: function(arg1, arg2) { 20 this.set('fooInvoked', YES); 21 this.set('arg1', arg1); 22 this.set('arg2', arg2); 23 } 24 }); 25 }, 26 27 teardown: function() { 28 Obj = obj = async = func = null; 29 } 30 }); 31 32 test("test async - SC.Async.perform('foo')", function() { 33 async = SC.Async.perform('foo'); 34 equals(SC.kindOf(async, SC.Async), YES); 35 equals(async.get('func'), 'foo'); 36 equals(async.get('arg1'), null); 37 equals(async.get('arg2'), null); 38 39 obj = Obj.create(); 40 async.tryToPerform(obj); 41 equals(obj.get('fooInvoked'), YES); 42 equals(obj.get('arg1'), null); 43 equals(obj.get('arg2'), null); 44 }); 45 46 test("test async - SC.Async.perform('foo', 'hello', 'world')", function() { 47 async = SC.Async.perform('foo', 'hello', 'world'); 48 equals(async.get('func'), 'foo'); 49 equals(async.get('arg1'), 'hello'); 50 equals(async.get('arg2'), 'world'); 51 52 obj = Obj.create(); 53 async.tryToPerform(obj); 54 equals(obj.get('fooInvoked'), YES); 55 equals(obj.get('arg1'), 'hello'); 56 equals(obj.get('arg2'), 'world'); 57 }); 58 59 test("test async - SC.Async.perform(function() { ... })", function() { 60 func = function() { this.foo(); }; 61 async = SC.Async.perform(func); 62 equals(async.get('func'), func); 63 equals(async.get('arg1'), null); 64 equals(async.get('arg2'), null); 65 66 obj = Obj.create(); 67 async.tryToPerform(obj); 68 equals(obj.get('fooInvoked'), YES); 69 equals(obj.get('arg1'), null); 70 equals(obj.get('arg2'), null); 71 }); 72 73 test("test async - SC.Async.perform(function() { ... }, 'aaa', 'bbb')", function() { 74 func = function(arg1, arg2) { this.foo(arg1, arg2); }; 75 async = SC.Async.perform(func, 'aaa', 'bbb'); 76 equals(async.get('func'), func); 77 equals(async.get('arg1'), 'aaa'); 78 equals(async.get('arg2'), 'bbb'); 79 80 obj = Obj.create(); 81 async.tryToPerform(obj); 82 equals(obj.get('fooInvoked'), YES); 83 equals(obj.get('arg1'), 'aaa'); 84 equals(obj.get('arg2'), 'bbb'); 85 }); 86 87 test("test async - SC.Async.perform('bar')", function() { 88 async = SC.Async.perform('bar'); 89 equals(async.get('func'), 'bar'); 90 91 obj = Obj.create(); 92 async.tryToPerform(obj); 93 equals(obj.get('fooInvoked'), NO); 94 });