除非调用done()回调,否则为什么调试器失败并且测试通过?

时间:2023-02-07 11:29:47

1) Can anyone explain why, when debugging this jasmine test for hapi, the debugger never hits any breakpoint inside the injected section (see comment) unless done is called later on? How can the absence of a line of code that is not yet reached affect the debugger earlier on ?

1)任何人都可以解释为什么在调试hapi的jasmine测试时,调试器永远不会在注入部分内部遇到任何断点(请参阅注释),除非稍后调用done?如何缺少尚未达到的代码行会影响之前的调试器?

I am aware that it is important to call the done method (which I have commented out on purpose). I am however surprised by the consequences.

我知道调用done方法很重要(我已经故意注释掉了)。然而,我对后果感到惊讶。

2) Another unfortunate side-effect of forgetting to call the done method is that the test always passes. Instead of passing I would rather see it fail if I make an error. Any suggestions?

2)忘记调用done方法的另一个不幸的副作用是测试总是通过。如果我犯了错误,而不是传递,我宁愿看到它失败。有什么建议?

const server = require("../lib/server");
describe("Server hello", function () {
 it("returns status code 200", function (done) {
  server.inject({ method: 'GET', url: '/' }, (res) => {
   // Never reached if done uncommented - even by debugger breakpoint - why?");
   console.log("GOT " + res.payload);
   expect(res.statusCode).toBe(200);
   // done(); // Test always passes if uncommented - is there any way to force an error instead?
  });
 });
});

1 个解决方案

#1


0  

Read the source, Luke! Jasmine docs for asynchronous testing note:

阅读来源,卢克!用于异步测试的Jasmine文档说明:

This spec will not start until the done function is called in the call to beforeEach above. And this spec will not complete until its done is called.

直到在上面的beforeEach调用中调用done函数之后,才会启动此规范。在完成调用之前,此规范不会完成。

So if you don't call done your suite is not run, not that it runs and times out!

因此,如果你没有调用完成,你的套件就不会运行,而不是它运行并超时!

#1


0  

Read the source, Luke! Jasmine docs for asynchronous testing note:

阅读来源,卢克!用于异步测试的Jasmine文档说明:

This spec will not start until the done function is called in the call to beforeEach above. And this spec will not complete until its done is called.

直到在上面的beforeEach调用中调用done函数之后,才会启动此规范。在完成调用之前,此规范不会完成。

So if you don't call done your suite is not run, not that it runs and times out!

因此,如果你没有调用完成,你的套件就不会运行,而不是它运行并超时!