JAsmineテストprototypeメソッド

3839 ワード

この小さいテストを書いて、jasmineの使い方を熟知しますsrc.js
var Class = function(){ };
Class.prototype.updateRoom = function(){ console.log('update') } module.exports = Class;

test.js
var Class = require('../src.js');
describe("A suite of basic functions", function() {
    beforeEach(function(){

        spyOn(Class.prototype,'updateRoom').and.callThrough();
        Class.prototype.updateRoom();
        // 
        //var c = new Class();
       // c.updateRoom();
    });

    it('test update',function(){
        expect(Class.prototype.updateRoom).toHaveBeenCalled();
    })

});




これは簡単すぎます.昇格版srcをください.js
var Class = function(){
};
Class.prototype.updateRoom = function(){
    console.log('update');
};

Class.prototype.createRoom = function(arg1,callback){
    if(!arg1)
        return callback(false);
    console.log(arg1);
    var c1 = new Class();
    c1.updateRoom();
}


module.exports = Class;

test.js
var Class = require('../../src/model/likaisrc.js');
describe("A suite of basic functions", function() {
    beforeEach(function(){
        var c = new Class();
        spyOn(Class.prototype,'updateRoom').and.callThrough();
        //Class.prototype.updateRoom();

       c.createRoom(jasmine.any(Object),jasmine.any(Function));
    });

    it('test update',function(){
        expect(Class.prototype.updateRoom).toHaveBeenCalled();
    })

});