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");
});
});