- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
根据 AngularJS 文档,指令 Controller 是:
instantiated before the pre-linking phase and it is shared with other directives if they request it by name (see require attribute). This allows the directives to communicate with each other and augment each other's behavior.
在 UI View 由容器和小部件组成的情况下,这听起来很棒且有用,小部件的链接函数可以通过声明性方法 require:^cotnainerDirective
在容器指令 Controller 中传递。这提供了回调容器行为的替代方法,而不是依赖事件的通信。
例如,一个需要容器 Controller 的小部件指令如下:
angular.module('platform').directive('widget', [ function ( ) {
return {
restrict: 'E',
transclude: true,
require: '?^container',
replace: true,
scope: {
layout: '=',
model: '='
},
templateUrl: 'js/modules/platform/templates/form-tmpl.html',
link: function (scope, element, iAttrs, requiredCtrl) {
if(requiredCtrl && requiredCtrl.fooMethod){
....
}
}
};
}]);
如果小部件位于容器内,则链接函数内的代码将执行额外的工作。该代码运行良好。然而,在对 widget 指令进行单元测试时,很难想到发送模拟容器指令 Controller 的好方法,因为它不是通过 Angular $injector 服务注入(inject)的。
可能,我需要从容器的 Angular 编写 UT,但这在某种程度上涉及引导容器指令所需的太多准备工作。有人以前遇到过这种情况并可以在这里分享一些好的观点吗?
最佳答案
事实证明,如果我想对小部件指令进行单元测试,它必须与容器松散地解耦,在这种情况下使用“require”并不是一个好主意,因为它实际上使小部件指令紧密依赖于容器。我已经改变了我的设计以使用事件驱动的通信 btw widget 和容器,这样我就可以简单地模拟事件监听器来监视 UT 中 widget 指令发送的事件。
关于javascript - 如何在指令 UT 中模拟所需的指令 Controller ,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/16514045/
我想为一个包含许多步骤的复杂算法编写 ut。例如,如下所示的算法类。我想测试每一步。但很明显我可以处理私有(private)函数。我正在使用谷歌 gtest。 如何设计UT? Class Algori
知道如何为下面的代码编写 UT 吗? public Set applyInitialDump(Map, List> centralModelRelated) { try {
我有一个公共(public)功能: virtual void foo(boost::optional p_param) = 0; 和它的模拟: MOCK_METHOD1(foo, void(boost
我有一个带有依赖项 B 的类 A。 我向 B::foo(String s1, String s2) 写入了一个 UT。假设我测试 B::foo("a", "a") 的流程 假设A::foo(..)调用
我正在用我的代码(C++、VS10)编写一个新的 UT。显然在测试中某处有错误。我在编译控制台看到如下错误 unknown location(0): fatal error in "Test1": b
例如,我有一个 java 类,如下所示。我要为 doWork() 编写一个单元测试,所以我想控制 obj 的行为。但是很明显obj是在内部实例化的。 这个UT怎么写?现在我正在使用 Junit+Moc
我有一个如下所示的 Controller (function () { var newPlaceController = function ($scope, PlacesService, $m
默认情况下,Docker 运行命令为容器使用专用的 UTS 命名空间,因此容器拥有自己的/唯一的主机名。我正在尝试在两个容器之间共享 UTS 命名空间,但似乎使用 docker run 命令是不可能的
我想知道为 Microsoft Visual Studio 单元测试断言类编写自定义扩展方法的最佳方法是什么。 最佳答案 您可以为此 Assert 创建扩展方法类。 Assert 类的版本现在为: p
我在使用 phpunit 时遇到了一个恼人的问题。我发现我的数据库没有更新,在触发一个 Eloquent 方法后,所以单元测试的结果总是错误的。 代码如下: $testTaskUser = TestT
根据 AngularJS 文档,指令 Controller 是: instantiated before the pre-linking phase and it is shared with oth
我想知道是否可以利用 Java 的 SimpleDateFormat 来解析时区 UCT 和 UT?例如 SimpleDateFormat format = new SimpleDateFormat(
因为将 1 个特定 React 组件的标记、样式和 javascript 放入 1 个单个文件中已成为一种常用模式。将单元测试(例如 mocha describes)放入同一文件也是一个好的模式吗?
我正在验证一个表单,在验证之后,我想使用 window.location = xxx 进行重定向,但它不起作用,除非我在它之后发出警报调用。 验证通过处理表单的 onsubmit 事件进行。 func
我正在开发一个 SpringBoot 应用程序,其中包含数十个带有数十种方法的 REST 端点。所有这些都使用 @RestController 注解进行声明。因此,出现了大量的 POJO,它们充当所有
关闭。此题需要details or clarity 。目前不接受答案。 想要改进这个问题吗?通过 editing this post 添加详细信息并澄清问题. 已关闭 9 年前。 Improve th
例子:JS 实用程序的功能如下: BDA.Utils.formatString = function (string) { (....) return someFormattedStr; } 现在
我有一个如下所示的 java 类。它的工作是监视一个文件,如果该文件的大小在一定时间间隔内没有变化,它就会发出警报。 我想为它写两个UT。 1.模拟文件大小保持不变。 2.模拟文件大小会保持一段时间的
我是 android 开发的初学者,希望得到以下解释, 我正在尝试在自定义对话框中获取用户输入。下面的代码有效。但是如果我更换 final EditText editText = (EditText)
我知道这是一个不平凡的问题,但上周我一直在思考如何做到这一点,但我找不到好的方法。 主要是我有一个 2D 关卡编辑器。我可以在世界中放置实体、添加瓷砖、碰撞等……我想要的是能够以可视化方式编写简单的脚
我是一名优秀的程序员,十分优秀!