我没有运气让PhantomJS / Grunt运行在浏览器中运行时运行良好的QUnit测试。
Gruntfile.js:
module.exports = function (grunt) {
grunt.initConfig({
pkg: grunt.file.readJSON('package.json'),
qunit: {
hello: ['test/helloQUnit.html']
}
});
grunt.loadNpmTasks('grunt-contrib-concat');
grunt.loadNpmTasks('grunt-contrib-connect');
grunt.loadNpmTasks('grunt-contrib-cssmin');
grunt.loadNpmTasks('grunt-contrib-qunit');
grunt.loadNpmTasks('grunt-contrib-watch');
grunt.loadNpmTasks('grunt-contrib-uglify');
grunt.loadNpmTasks('grunt-md2html');
grunt.registerTask('default', ['qunit']);
};
测试.html:
<!DOCTYPE html>
<html>
<head>
<title>Hello QUnit</title>
<script type="text/javascript" src="vendor/qunit.js"></script>
<link rel="stylesheet" href="vendor/qunit.css" type="text/css"/>
<script type="text/javascript" src="//ajax.googleapis.com/ajax/libs/jquery/1.11.1/jquery.min.js"></script>
</head>
<body>
<div id="qunit"></div>
<div id="qunit-fixture"></div>
<script type="text/javascript" src="helloQUnit.js"></script>
<script type="text/javascript">
document.addEventListener('DOMContentLoaded', function () {
helloQUnitTests();
});
</script>
</body>
</html>
测试.js function helloQUnitTests(){
test( "Passing QUnit Test", 1, function() {
var value = "hello";
equal( value, "hello");
});
test(“Failing QUnit Test”,1,function(){ var number = 5; 相等(数字,7); });
}
我不知道如何调试它。有什么想法吗?我在这里错过了什么?