簡體   English   中英

摩卡“每個鈎子之前”錯誤消息

[英]Mocha 'before each hook' error message

測試失敗之前,我收到以下消息

下面是我的代碼

before(function(done) {
  function afterListening() {
    customFormats(ZSchema);
    done();
  }

  if (app.server.listening) return afterListening();

  app.on('listening', afterListening);
});

describe('/a1/{exampleID}', function() {
  describe('get', function() {
    it('should respond with 200 Return an array of shelter...', function(done) {
      /*eslint-disable*/
      var schema = {
        "type": [
          "object",
          "null"
        ],
        "properties": {
          "meta": {
            "type": [
              "object",
              "null"
            ],
            "properties": {
              "resource": {
                "type": [
                  "string",
                  "null"
                ],
                "description": "fully qualified URL call"
              },
              "version": {
                "type": [
                  "string",
                  "null"
                ],
                "description": "version of API being called"
              },
              "response": {
                "type": [
                  "integer",
                  "null"
                ],
                "format": "int32",
                "description": "status code"
              },
            "required": [
              "version",
              "resource"
            ]
          } 
        }
      };

      /*eslint-enable*/
      api.get('/a1/example/64442')
      .set('Content-Type', 'application/json')
      .expect(200)
      .end(function(err, res) {
        if (err) return done(err);

        validator.validate(res.body, schema).should.be.true;
        done();
      });
    });
});
});

錯誤 1)示例“在每個之前”掛鈎:錯誤:超過200毫秒的超時。 確保此測試中調用了done()回調。 為空。 (LIB / runnable.js:170:19)

僅當我在計算機上運行測試用例時才會出現此錯誤。如果我在另一台計算機上運行相同的測試用例,則測試用例正在通過。 為什么會發生。看到這樣的樣子很奇怪。

任何幫助,請!

當您未按預期返回承諾時,通常會收到超時錯誤。

已完成,但不再需要。 如果您使用的是Mocha的最新版本,則應該能夠僅返回promise,而不必調用Done()。

這是有關Mocha-as-promised的詳細信息-自1.18.0版本以來已與默認Mocha集成。

您應如何返回承諾的示例:

it("should be fulfilled with 5", function () {
  return promise.should.become(5);
});

在beforeeach的情況下-實現應如下所示:

beforeEach(() => {
 const {col1, comments} = mongoose.connection.collections;

 return col1.drop(() => {
    // Do something after collection is dropped
 });
});

通知return對於在eacheach內采取的操作。

您能否與我們分享之前的信息,以便我們提供幫助?

不看,可能是因為您與要連接的任何事物的連接未按時響應或根本沒有響應。

可能想檢查您與單元測試所連接位置的連接(可能是因為它是數據庫,因為它位於beforeEach()beforeEach()不需要在其中調用done()

將您的超時時間增加到10秒左右。 如果沒有收到數據庫錯誤,則連接速度很慢。 如果即使在10秒后仍然出現超時錯誤,則可能根本沒有連接。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM