1)谁能解释一下,为什么在为hapi调试这个jasmine测试时,调试器永远不会命中注入部分中的任何断点(参见注释),除非稍后调用done?缺少一行尚未到达的代码会如何影响前面的调试器?
我知道调用done方法是很重要的(我已经特意注释掉了它)。然而,我对其后果感到惊讶。
2)忘记调用完成方法的另一个不幸的副作用是测试总是通过。如果我犯了一个错误,我宁愿看到它失败,而不是通过。有什么建议吗?
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?
});
});
});发布于 2016-08-16 16:06:59
Read the source, Luke! Jasmine docs异步测试注意事项:
在上面对beforeEach的调用中调用
函数之前,此规范将不会启动。在调用它的完成之前,这个规范将不会完成。
所以,如果你不调用done,你的套件就不会运行,而不是,它会运行并超时!
https://stackoverflow.com/questions/38969188
复制相似问题