gpt4 book ai didi

javascript - Buster JS - BDD 风格 - 设置规范超时

转载 作者:行者123 更新时间:2023-11-30 18:06:47 25 4
gpt4 key购买 nike

在 javascript 中将 buster.js 用于 BDD,我有一些相当庞大的 API 需要测试。在某些情况下,默认超时不会为我做这件事。如何覆盖(异步)规范的默认超时?

describe("Given a request for all combinations", function() {

var scenario = null, spec;

beforeAll(function() {
scenario = scenarios.buildFakeAPI();
});

before(function(done) {

spec = this;

// *** this request can take up to 60 seconds which causes a timeout:
scenario.request({ path: "/my/request/path" }, function(err, res) {

spec.result = res;
done();
});
});

it("it should have returned the expected thing", function() {
expect(spec.result).toMatch(/expected thing/);
});
});

最佳答案

我遇到了同样的问题,下面的似乎解决了它。

当不使用 BDD 时,可以在 setUp 函数中设置超时

buster.testCase("MyTest", {
setUp: function() {
this.timeout = 1000; // 1000 ms ~ 1 s
}
});

当使用 BDD 表示法时,我们可以在 beforeAll 函数中做同样的事情

describe("MyTest", function() {
before(function() {
this.timeout = 1000 * 60; // 60000 ms ~ 60 s
});
});

关于javascript - Buster JS - BDD 风格 - 设置规范超时,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/15633792/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com