写这个小测试,熟悉下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();
})
});