if (typeof define !== 'function') {
    var define = require('amdefine')(module);
}

define(["require","../deep", "../deep-unit"], function (require, deep, Unit) {
    
    //_______________________________________________________________ GENERIC STORE TEST CASES


    var unit = {
        title:"deep/units/chain",
        stopOnError:false,
        tests : {
            delayed_run_return:function(){
                return deep({
                    a:true
                })
                .run(function(){
                    this.b = true;
                    return deep(this).delay(5);
                })
                .equal({ a:true, b:true });
            },
            delayed_run_call:function(){
                return deep({
                    c:function(){
                        return "c returned";
                    }
                })
                .run("c")
                .equal("c returned");
            },
            branch1:function(){
                return deep({
                    test:1
                })
                .branches(function(b){
                    b.branch().equal({test:1}).delay(10).when("branch 1");
                    b.branch().equal({test:1}).delay(5).when("branch 2");
                    return b;
                })
                .equal(["branch 1","branch 2"]);
            }
        }
    };

    return new Unit(unit);
});

@@ -1332,16 +1332,1080 @@
 h 2%22%5D);%0A
+            %7D,%0A            listened_chain:function()%7B%0A                var d = deep(1)%0A                .delay(5)%0A                .done(function(s)%7B%0A                    return %22delayed%22;%0A                %7D);%0A                var d2 = deep.when(d)%0A                .done(function()%7B%0A                    d.log(); // error : chain was ended%0A                %7D)%0A                .fail(function(e)%7B%0A                console.log(%22eneded chain error : %22, e.status);%0A                    if(e.status === 1001)%0A                        return true;%0A                %7D);%0A                var d3 = deep(%7B%7D).delay(5);%0A                try%7B%0A                    d.log(); // error : chain is listened%0A                %7D%0A                catch(e)%0A                %7B%0A                console.log(%22catched errorr : %22,e)%0A                    if(e.status === 1001)%0A                        d3.when(true);%0A                    else%0A                        d3.when(e);%0A                    //console.log(%22normal error : chain is listened ! : %22, e)%0A                %7D%0A                return deep.all(d2, d3);%0A
         

add listened test unit in deep/units/chain