2017-04-03 17 views
0

私はこのバグを見てみましたが、私のバグに答える答えを見つけられないようです。私はいくつかのAPIをテストするためにmochaとchai-httpを使用しています。私は、対応するRESTFULメソッド(POST、GET、PUT)を使用してエンドポイントに当たっていて、応答をチェックしています(実際はまっすぐです)。問題は個々に私のテストスイートが動作することです(私が一度に1つずつ実行するのであれば)。しかし、私がgulpコマンドを使って実行すると、いくつかのテストケースに対して "コールバックは機能しません"ここでもしフック中のものあなたはモカに精通している場合)コールバック関数ではありません - Mocha/Mongoose

は私が取得していますエラーです:

Uncaught TypeError: callback.apply is not a function 
      at Immediate.<anonymous> (node_modules/mongoose/lib/model.js:3683:16) 
      at Immediate._onImmediate (node_modules/mongoose/node_modules/mquery/lib/utils.js:137:16) 

は、ここに私のテストケースが存在する私のディレクトリの構造です:

test 
    backend 
     assignments_tests.js 
     application_tests.js 
     courses_test.js 

&私は次のファイルを持っています:

// Set the environment variable for the test cases to point to production 
gulp.task('set-testing-env', function() { 
    return process.env.NODE_ENV = 'production'; 
}) 

// gulp task for backend 
gulp.task('test-backend', ['set-testing-env'], function() { 
    return gulp.src('test/backend/**/*.js', {read: false}) 
    .pipe(mocha({ 
     reporter: 'spec', 
     timeout: 60000 
    })) 
    .on('error', function(err) { 
     // console.log(err); 
     process.exit(); 
    }); 
}); 

&最終的に私のテストケースのサンプル:私は、コールバック関数ではないエラーを取得していますなぜ

describe("testing GET" .... 
    before(function(done) { 
     ... setting up stuff here and calling done ... 
    }) 

     describe("get courses information and courses offered", function() { 
     it("gets a courses information", function(done) { 
      const endpoint = test.endpoint + "/courseInfo/" + test.course 
      chai.request(app) 
       .get(endpoint) 
       .end(function(err, res) { 
       expect(err, "Error hitting endpoint").to.be.null; 
       expect(res, "Expected data in json format").to.be.json; 
       expect(res, "Expected status to be 200").to.have.status(200); 
       expect(res.body, "Expected course info!").to.have.length(1); 
       expect(res.body[0],"Missing keys").to.have.all.keys(courseInfo); 
       done(); 
       }) 
     }) 
    }) 

    describe("testing POST" ... 
    before(function(done) { 
     ... setting up and calling done ... 
    }) 

    describe(... 
     it(...) 
    }) 
    }) 

私もよく分かりません。 :( すべてのヘルプははるかに高く評価されるだろう

答えて

0

をおそらくあなたは、この問題のようなパラメータとして、あまりにも多くのオブジェクトのようなものを渡しマングースメソッドを呼び出しているここでは含まれていませんでしたコードの一部に:!

それらの目的の一つは、関数として解釈されますが、このようなとして呼び出すことはできません

これは共通の問題であるが、あなたはdidnの; TI Mongooseメソッドを実行するコードは除外されているので、それがここで問題になるかどうかは分かりません。

関連する問題