开玩笑-取消测试的正确方法

时间:2020-04-27 15:07:13

标签: node.js typescript testing jestjs

我有一个NodeJS应用程序,并且我使用Jest进行测试。

我的应用程序使用ElasticSearch,并且在beforeAll中,我检查是否确实存在ElasticSearch。如果不是这种情况,我想取消测试(因为用户可能只是忘记了启动它。)

当前,我要退出process.exit

beforeAll(async () => {
    await esClient.ping({
        requestTimeout: Infinity,
        hello: 'elasticsearch!'
    }, function (error) {
        if (error) {
            console.error('Couldn\'t connect to ElasticSearch! Is it launched?');
            process.exit(1);
        }
    });
});

这有效,但玩笑会重试5次,然后放弃。我可以将开玩笑的重试次数更改为1,但我觉得有更好的方法。

那么,有没有一种明确的方法告诉玩笑“ 立即取消所有内容。”?

0 个答案:

没有答案