Использует Promise лучшее решение вместо тайм-аута для тестирования API - mocha - PullRequest
0 голосов
/ 19 мая 2018

Является ли использование Promise лучшим решением вместо использования timeout для тестирования API с использованием mocha / chai?Я получаю ошибку, подобную этой, для многих тестов и хочу предотвратить эти ошибки.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')

      });
 });

1 Ответ

0 голосов
/ 22 мая 2018

Спасибо за комментарии, которые помогли мне получить ответ.На данный момент (поскольку я не хочу издеваться над ответом) помогло редактирование конфигурации (увеличение времени ожидания).

 // 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
});
...