1
如何使用qUnit测试javascript 打印方法?如何使用qUnit测试JavaScript打印方法?
我有一个名为core.js建立在jQuery的文件 -
// API
var Screen = (function() { // private methods
function print(text) {
document.write(text);
}
return { // public methods
print: function (text) {
print(text);
}
};
}());
// MAIN
$(function() { // document ready
Screen.print("Hello World.");
});
我还设置了qunit.js(和.css)文件的HTML文档中:
<!DOCTYPE html>
<html>
<head>
<link href='qunit.css' rel='stylesheet' />
</head>
<body>
<div id='qunit'></div>
<script src='qunit.js'></script>
<script src='core.js'></script>
</body>
</html>
我在想,我必须添加一个脚本标记到导入core-test.js的HTML文档中,它包含我的单元测试。这是我弄糊涂......
核心test.js:
$(function() {
test("print", function() {
ok(Screen.print(text), "String is NOT null or undefined");
});
});