代码-1:
describe("testing server functionalities", () => {
// test case
it("server handles a function", () => {
request('some link', (error, response, body) => {
var expected = "1410";
expect(expected).to.be.equal(body);
})
})
});代码-2:
describe("testing server functionalities", () => {
// test case
it("server handles a function", (done) => {
request('some link', (error, response, body) => {
var expected = "1410";
expect(expected).to.be.equal(body);
done();
})
})
});因此,在Code-1中,由于请求调用是异步的,所以在检查value是否满足expected value之前,我们遇到了测试退出的问题。
为了处理这个问题,我找到了一种方法,在done中引入的参数Code-2使测试函数等待done()函数的调用,这最终使测试函数正常工作。
但是我不知道Code-2是如何工作的,为什么测试函数要等待done。
有人能帮我吗?
发布于 2021-08-25 19:43:37
Here,您可以看到我们如何知道函数需要哪些参数。
这是最简单的。
另外,还可以通过将JS-文件解析为抽象语法树(AST)来获得这些参数。
然后,就可以很容易地创建不同的逻辑。
让我们想象一下它的外观(抽象为):
// Some testing framework code
const shouldWaitUntilDone = testcase.hasDoneCallback();
if (shouldWaitUntilDone) {
// Callback will run when done() is called
testcase.run(() => { testcase.runMatchers(); })
} else {
testcase.run().runMatchers();
}https://stackoverflow.com/questions/68928422
复制相似问题