0
我的JS文件(我需要測試)是/JasmineTest/src/mySource.js。它有myObj
對象無法指定Karma中的JavaScript文件路徑
myObj={
setA:function(value){
a=value;
},
getA:function(){
return a;
},
};
我的茉莉花規範文件是/JasmineTest/spec/mySpec.js。它測試myObj
describe("Jasmine sample suite",function(){
it("tracks that spy was called",function(){
expect(myObj.getA).toHaveBeenCalled();
});
因果報應,我指定的規範文件位置爲
files: [
'spec/*.js'
],
,當我在/ JasmineTest開始噶,這個測試給錯誤
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')
將其導入到spec文件中,但出現錯誤require is not defined
如何使myObj在規格文件中可見?
我不知道如何使用webpack等,所以嘗試了第二種方法。 –