使用jasmine-node进行单元测试,生成的测试报告提示ReferenceError: require is not defined 代码如下:
version_ip.js
var fs = require(‘fs’); exports.version_ver = function(path,cb){ fs.readFile(path, 'utf-8’, function(err, data){ if(err) throw err; var data1 = data.split(‘\r’); // console.log(version[1]); var version1 = data1[1].split(‘=’); var version_num = version1[1].trim(); // console.log(version_num); cb(null, version_num); }) ; } ;
check.spec.js
describe("check version and ip", function(){ var version_ip = require(“…/app/version_ip”); var path_ver = 'D:/webstrom_node/nodejs/version.ini’; var expect_ver = '0801004067’; var num;
beforeEach(function(){
}) ;
it("version.ini zhong version hao jian cha", function(){
version_ip.version_ver(path_ver, function(err, actual){
if(err) throw err;
num =actual;
console.log("Actual"+actual);
console.log("NUM"+num);
expect(num).toEqual(expect_ver);
}) ;
});
}) ;
执行check.spec.js文件后,查看生成的报告,如图: