我正在为一个函数编写测试代码,该函数将检查 twitter 中是否存在用户名。我正在使用 Hapi 框架和实验室进行测试。
当我运行时,npm test
我收到以下错误:
> NameGen@0.0.0 test /Users/mario/projects/NameGen
> ./node_modules/lab/bin/lab -c
/Users/mario/projects/NameGen/test/test.js:5
Lab.experiment( "Test Username Existence", function() {
^
TypeError: Object #<Object> has no method 'experiment'
at Object.<anonymous> (/Users/mario/projects/NameGen/test/test.js:5:5)
at Module._compile (module.js:456:26)
at Object.Module._extensions..js [as origLoader] (module.js:474:10)
at Object.require.extensions..js (/Users/mario/projects/NameGen/node_modules/lab/lib/coverage.js:32:26)
at Module.load (module.js:356:32)
at Function.Module._load (module.js:312:12)
at Module.require (module.js:364:17)
at require (module.js:380:17)
at /Users/mario/projects/NameGen/node_modules/lab/lib/cli.js:85:23
at Array.forEach (native)
at Object.internals.traverse (/Users/mario/projects/NameGen/node_modules/lab/lib/cli.js:81:19)
at Object.exports.run (/Users/mario/projects/NameGen/node_modules/lab/lib/cli.js:30:29)
at Object.<anonymous> (/Users/mario/projects/NameGen/node_modules/lab/bin/lab:3:23)
at Module._compile (module.js:456:26)
at Object.Module._extensions..js (module.js:474:10)
at Module.load (module.js:356:32)
at Function.Module._load (module.js:312:12)
at Function.Module.runMain (module.js:497:10)
at startup (node.js:119:16)
at node.js:906:3
npm ERR! Test failed. See above for more details.
npm ERR! not ok code 0
我的测试代码是:
var Lab = require("lab");
var server = require('../'); // require index.js
var request = require('request');
Lab.experiment( "Test Username Existence", function() {
// tests
Lab.test( "Test username exists", function(done){
var options = {
url: 'http://twitter.com/BarackObama'
};
request(options, function(error, response, body){
Lab.expect(response.statusCode).to.equal(200);
});
done();
});
Lab.test("Test username does not exists", function(done){
var options = {
url: 'http://twitter.com/jhkhksdhkjahsdfkjhasdf'
};
request(options, function(error, response, body){
Lab.expect(response.statusCode).to.equal(404);
});
done();
});
});
package.json
我在我的文件中安装了最新版本的节点和所有必要的依赖项。什么可能导致此错误?