我有一个问题,我在Karma运行我的茉莉花单元测试,并且我的一个单元测试依赖于外部模板(AngularJS指令)没有通过。当我在浏览器中进入DEBUG模式,然后查看控制台时,它显示此单元测试已通过,我可以在浏览器调试器中单步测试时确认这一点。Karma测试失败,但调试显示通过
我还有其他的单元测试,也取决于外部模板,正如预期的传递在Karma中,但只是这个特定的测试在Karma失败,但通过浏览器控制台。
有没有人有任何想法可能会导致此行为?
编辑:
这里是噶表示:
TypeError: Unable to get value of the property 'then': object is null or undefined
我的项目处理模板一点不同于AngularJS通常处理它们。我们有我们创建了一个templateService它检索基于一个指令,它看起来像这样
templateUrl: "navigation-template"
所以我已经建立了噶拉模板,并将其存储在templateCache的templateUrl正确的模板。然后,我使用关键的Karma(文件路径)提取模板,并使用指令所期望的templateUrl将它们重新插入到templateCache中。以下是我如何做
var template = '<div>' + templateCache.get(templateFilePath) + '</div>'; }
// template files contain multiple templates so this filters out the one I want
template = $("[TemplateId='" + directiveTemplateUrl + "']", template).html();
templateCache.put(directiveTemplateUrl, template);
对于所有其他测试,这工作正常,但一个特别是产生上述错误。更有趣的是,如果我添加这样的控制台日志
var template = '<div>' + templateCache.get(templateFilePath) + '</div>';
if (template.indexOf("undefined") > -1) { throw new Error("Template not in cache."); }
template = $("[TemplateId='" + directiveTemplateUrl + "']", template).html();
if (!template) { throw new Error("Template not found."); }
templateCache.put(directiveTemplateUrl, template);
它注销该模板找不到。
Error: Template not in cache.,Error: Unexpected request: GET navigation-template No more request expected
如果我调试在浏览器中(当噶加载浏览器中的DEBUG按钮),我可以证实的模板是存在的,在浏览器控制台(不到哪噶运行命令行,但F12开发在浏览器工具),它记录的是测试成功这样
LOG: SUCCESS ButtonsDirectives NavigationDirective Should render a loading message
这是我知道的:
有失败的单元测试和传球者之间没有显著差异。它与单元测试运行的顺序无关(这只是刚好运行)。
“传入浏览器控制台”是什么意思,测试失败时会出现什么错误?当您逐步调试调试器中的代码时,它会通过这一事实,这听起来像是一个计时问题。 –
您可以发布浏览器控制台中的内容吗? – MarcoL
@SunilD。我认为*用“DEBUG”表示在Karma中的调试窗口,它不是JS调试器。 – MarcoL