[英]How to unit test functions in a module?
I'm new to a project where there is a JavaScript script a3.panel.js
written by someone else. 我是一个新项目,其中有一个由其他人编写的JavaScript脚本
a3.panel.js
。 It defines an module like this: 它定义了一个这样的模块:
a3.panel = (function () {
let property1 = {},
property2 = $('.checkbox');
function someMethods () {
some logic
};
return ({
some value
});
})();
with Jasmine, how can I test the method inside this module? 使用Jasmine,我该如何测试该模块中的方法? I tried
我试过了
describe("panel test", () => {
it("should test", () => {
var panel = a3.panel;
expect(typeof a3.panel.property1).toBe("object");
});
});
and Jasmine returns: 和Jasmine回归:
ReferenceError: a3 is not defined
I guess the external library is not loaded for the test. 我想外部库没有加载测试。
Can you try this in your Jasmine test (I haven't tried yet)- 你可以在你的Jasmine测试中尝试这个(我还没试过) -
document.write('<script src="http://.../a3library.js></script>')
You may provide local path too. 您也可以提供本地路径。
OR 要么
Use jQuery GetScript 使用jQuery GetScript
And 和
Check this too - include external Javascript as a source to Jasmine 检查一下 - 包括外部Javascript作为Jasmine的源
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.