[英]How to ensure that jasmine's expect() was executed in test
我对角应用有这样的测试:
it("should return false if all products loaded", function () {
$httpBackend.flush();
scope.loadNextProducts(15).then(function (isThereMoreToLoad) {
expect(isThereMoreToLoad).toBe(false);
});
scope.$apply();
});
如果我忘了写ether $httpBackend.flush();
或scope.$apply();
测试永远不会达到expect()
部分,测试将成功。
有没有办法确保茉莉花测试执行expect(),如果没有,那么它应该失败?
有点像指定it()
expect()
多少expect()
或者告诉jasmine每个测试应该执行至少一个expect()
否则它应该失败。
尝试这个:
afterEach(function() {
$httpBackend.verifyNoOutstandingExpectation();
$httpBackend.verifyNoOutstandingRequest();
});
那应该是,验证您的测试没有未访问过的期望,并且还应验证是否已调用所有预期的服务器调用。
您可以在Angular $后端文档中找到更多信息
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.