咕噜摩卡没有发现目标的错误

我正在尝试使用grunt,mocha和chai编写节点api的testing。 我不知道如何require其他库。 我是一个初学者,咕噜,摩卡,柴,和一般的testing…

我的Gruntfile:

 // Gruntfile.js module.exports = function(grunt){ grunt.initConfig({ pkg: grunt.file.readJSON('package.json'), // Mocha Test mochaTest: { test: { options: { reporter: 'list', timeout: 15000 }, src: ['test/groupstest.js'] } } }); // Load grunt mocha task grunt.loadNpmTasks('grunt-mocha'); grunt.loadNpmTasks('grunt-mocha-test'); }; 

文件结构:

 ├── package.json ├── Gruntfile.js ├── test │  └── groupstest.js └── ... 

groupsheets:

 'use strict'; var request = require('supertest'); var expect = require("chai").expect; var app = require('../middleware/express'); describe('Routes', function(){ describe('/groups - GET', function(){ it('- should GET users', function(done){ console.log(request(app).get); request(app) .get('/groups', function(err, res, body){ ... done(); }); }); }); 

我正在模拟app.js文件中的快速应用程序。 然后我正在testing一个GET路由,但它说“要求”没有定义。 任何想法如何能解决这个问题? 我觉得我真的很接近。


更新:所以我inputgrunt mochaTest来testing这个。 问题是,它是超时,我不明白为什么。

这是错误:

  Routes /groups - GET - should GET users: [Function] 1) Routes /groups - GET - should GET users 0 passing (15s) 1 failing 1) Routes /groups - GET - should GET users: Error: timeout of 15000ms exceeded. Ensure the done() callback is being called in this test. Warning: Task "mochaTest:test" failed. Use --force to continue. Aborted due to warnings. 

你的问题涉及到你使用超级的方式。 查看下面的代码片段作为例子。

 it('- should GET users', function(done){ request(app) .get('/groups') // you can add supertest expectations here .end(function(err, res){ ... done(); }); });