getaddrinfo ENOTFOUND在使用节点中的Hapijs和Lab进行测试时未定义

时间:2015-08-10 11:07:41

标签: javascript node.js unit-testing hapijs lab

当我尝试测试我的API时,使用Lab模块用Hapijs编写,我有这个错误:

  

首选项返回200个HTTP代码,用于make:

  getaddrinfo ENOTFOUND undefined

  at errnoException (dns.js:44:10)
  at GetAddrInfoReqWrap.onlookup [as oncomplete] (dns.js:94:26)

测试目录中的文件index.js是:

'use strict';

var Lab = require('lab');

var Code = require('code');
var Hapi = require('hapi');
var Joi = require('joi');

// internal object
var internals = {};

// Test shortcuts
var lab = exports.lab = Lab.script();
var experiment = lab.experiment;
var describe = lab.describe;
var it = lab.it;
var before = lab.before;
var expect = Code.expect;

describe('Preferences', function() {

it("return 200 HTTP code wfor the make", function(done) {

  var server = new Hapi.Server();
  server.connection();
  server.route({
      method: 'GET',
      path: '/makes',
      config: {
          handler: require('../handlers/cars').getMakes,
          validate: {

          }
      }
  });

  server.inject({
      method: 'GET',
      url: '/makes',

  }, function(res) {
      expect(res.statusCode).to.equal(200);
      done();
  });
 });
 });

文件route.js是这样的:

module.exports = [{
path: '/makes',
method: 'GET',
config: {
//auth: 'session', only for testing disable the auth
auth: 'false',
handler: cars.getMakes
}

我已经解除了此测试的身份验证,处理程序是这样的:

getMakes: function (request, reply) {
Make
  .find()
  .sort('name')
  .exec( function(err, result) {

      if (err) {
         request.log(['server', 'database', 'error'], 'An error occured during the execution of the query');
     }

     return reply(result)
        .code(200);
    });

}, 你能解释一下错误在哪里以及为什么它会向我显示这种错误类型?

0 个答案:

没有答案