我的JS文件(我需要测试)是/JasmineTest/src/mySource。js。它有
myObj
myObj={
setA:function(value){
a=value;
},
getA:function(){
return a;
},
};
我的Jasmine规范文件是/JasmineTest/spec/mySpec。js。It测试
myObj公司
describe("Jasmine sample suite",function(){
it("tracks that spy was called",function(){
expect(myObj.getA).toHaveBeenCalled();
});
files: [
'spec/*.js'
],
当我在/JasmineTest中启动Karma时,测试会出错
Chrome 60.0.3112 (Windows 10 0.0.0) Jasmine sample suite tracks that spy was called FAILED
ReferenceError: myObj is not defined
at UserContext.<anonymous> (spec/mySpec.js:4:9)
我试着导出myObj
module.exports = myObj;
并使用
require('../src/mySource.js')
require is not defined
如何使myObj在specs文件中可见?