【问题标题】:Testing nested Angular directives with Jasmine使用 Jasmine 测试嵌套的 Angular 指令
【发布时间】:2015-07-29 16:07:28
【问题描述】:

我有一个自定义的角度指令(顶级指令),它在它的模板主体中将值传递给其他 2 个指令(子指令)。

我必须编写一个集成测试,如果子指令接收到由顶级指令传递的正确值,但是当我 $compile(topLevelDirectiveHtml)(scope) 时,它的 HTML 不包含评估值,而是在子指令中评估的 HTML 中,我得到的只是模板,其中包含对模型的引用......举个例子:

$scope.myModel = true;
<topLevelDirective testValue="myModel" />

编译后会得到如下代码

directive.scope.subValue = myModel;
<subDirective subTestValue="subValue" />

我需要验证subDirective编译后,“subTestValue”属性的值为“true”,但其值为“subValue”

【问题讨论】:

  • 你能否提供更多关于你的指令的细节,包括它们的模板和它们的 angularjs 声明?

标签: angularjs jasmine tdd bdd


【解决方案1】:

你必须在你的作用域上分配“subValue”,例如:

scopeFake.subValue = true;

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2015-01-18
    • 1970-01-01
    • 1970-01-01
    • 2013-03-30
    • 2018-09-30
    • 1970-01-01
    • 2013-01-23
    • 2013-08-25
    相关资源
    最近更新 更多