-1

使用Promise是更好的解决方案,而不是使用 mocha/chai 进行 API 测试超时?对于很多测试,我在下面遇到这样的错误,并希望防止这些错误。Error: timeout of 2000ms exceeded. Ensure the done() callback is being called in this test.

describe('Email Tests', function() {
            let messagingApiPath = '/v2/email';
            let testData = require(`../../${testJsonFileName}`);

            let positiveAssertions = function(response) {
                console.log('Response : \n', response.text);
                expect(response.statusCode).equals(200);
                expect(response.status).equals(200);
                expect(response.emailReferenceId == 36);
            };

            describe('POST /v2/email with TO and CC', function() {

                console.log('Test Data File: ' + testJsonFileName);
                describe('with To:  CC:  Test-Case-1', function() {
                    it('response with email id reference expected', function(done) {

                        request
                            .post(messagingApiPath)
                            .send(input)
                            .expect((response) => positiveAssertions(response))
                            .end(done);
                    });
                });
          //many more tests like  describe('POST /v2/email')

      });
 });
4

1 回答 1

0

感谢您的评论帮助我找到答案。现在(因为我不想模拟响应)编辑 grunt 配置(增加超时)有所帮助。

 // Grunt initial configuration
grunt.initConfig({
    pkg: grunt.file.readJSON('package.json'),
    mochaTest: {
        unit: {
            options: {reporter: 'spec'},
            src: ['test/lib/setup.js', 'core/test/**test.js']
        },
        functional: {
            options: { reporter: 'spec', timeout: 40000 },
            src: ['test/functional/setup.js','test/functional/v1/mytests.js']
        }
    },
    //more code that is removed for simplicity
});

于 2018-05-21T22:37:52.897 回答