Moock example 3

Demonstrating the Mock Mutator

by ariehg

HTML

<script src="http://blog.arieh.co.il/js/Moock.js"></script>
<script src="http://blog.arieh.co.il/js/Mock.js"></script>

JavaScript

/* some simple tet loging */
Moock.Libraries.jsfiddle = {
    check: true
    , isTrue : function(expr,msg){
        if (!expr) console.log(msg);
    }
    , areEqual :function(exp,act,msg){
        if (exp[0] && (exp[0]!=act[0])) console.log(msg);
        if (typeof exp == 'number' && exp!=act) console.log(msg);
    }
};

/* a class we're developing - only has partial behavior */
var ClassA = new Class({
        logA : function(){
           console.log(this.a("aaa"));
        } 
    })
    /* we will use this mock to test the behavior of logA */
    , MockA  = new Class({
        Extends : ClassA
        , Mock : {
            /* the name is the method to be Stubbed, 
               the value is the returedValue  */
            a : "aaa" 
        }
    })
    , mock = new MockA;


mock.a.called(2).receive(["aaab"]);
mock.logA();
mock.a.test();