0
我想添加一个测试,它将覆盖CommonJS文件module1.js
中的返回语句,请参阅附加图像。karma-jasmine - 如何测试返回对象
这里就是我目前正试图:
describe("Module 1 ",() => {
let mod, testMod = null;
beforeEach(() => {
mod = {
module1: require('../src/app/js/module1/module1')
};
spyOn(mod, 'module1');
testMod = mod.module1();
console.log(testMod);
console.log(mod.module1);
});
it('is executed',() => {
expect(mod.module1).toHaveBeenCalled();
});
});
模块1文件:
/**
* Represents module1.
* @module module1
*/
function module1() {
let x = 13;
return {
getUserAgent: getUserAgent
};
/**
* Return the userAgent of the browser.
* @func getUserAgent
*/
function getUserAgent() {
return window.navigator.userAgent
}
}
module.exports = module1;
日志输出:
LOG: undefined
LOG: function() { ... }
更新:当我登录mod.module.toString
,控制台日志:
function() { return fn.apply(this, arguments); }
为什么我的模块不在那里?
我在这里尝试正确的方法吗?为什么不mod.module1();
工作?