我正在写两个包含ui-bootstrap的tabset和tab指令的指令.
为了将我的指令的内容传递给包装指令,我在两个指令中使用了转换.
这很有效,唯一的问题是我没有编写检查它的测试.我的测试使用替换指令作为包装指令的模拟,我在每次测试之前使用$ compileProvider替换它.
测试代码看起来像这样:
beforeEach(module('myModule', function($compileProvider) {
// Mock the internally used 'tab' which is a third party and should not be tested here
$compileProvider.directive('tab', function() {
// Provide a directive with a high priority and 'terminal' set to true, makes sure that
// the mock directive will get executed, and that the real directive will not
var mock = {
priority: 100,
terminal: true,
restrict: 'EAC',
replace: true,
transclude: true,
template: '<div class="mock" ng-transclude></div>'
};
return mock;
}); …Run Code Online (Sandbox Code Playgroud) 我们有一个角度应用程序(SPA),它维护客户端用户会话(会话超时,不活动时间等).会话用于强制用户在会话因某种原因到期时重新登录.
会话的到期由专用服务控制,该服务在会话终止,锁定或以其他方式更改状态时在$ rootScope上广播事件.
我们将侦听器添加到那些会将路由更改为相关页面(登录页面,解锁页面等)的会话状态更改事件.我们使用angular-ui-router进行路由.
这很好,但是,特别是在Firefox中,如果在浏览器窗口/选项卡未激活(即最小化,在后台等)时会发生会话状态更改,则页面不会正确刷新.换句话说,您可以看到新页面的控件(例如用户名文本字段和密码字段),但不会看到新页面的背景,而是看到旧页面的背景.
它在Chrome和IE中完美运行,我们只在Firefox上看到这个问题.此外,当浏览器窗口/选项卡处于活动状态时,它也可以在Firefox上完美运行.
有什么想法吗 ?
任何人都可以向我解释为什么下面的两个函数a和b行为不同.函数在本地a更改names并b更改实际对象.
我在哪里可以找到这种行为的正确文档?
def a(names):
names = ['Fred', 'George', 'Bill']
def b(names):
names.append('Bill')
first_names = ['Fred', 'George']
print "before calling any function",first_names
a(first_names)
print "after calling a",first_names
b(first_names)
print "after calling b",first_names
Run Code Online (Sandbox Code Playgroud)
输出:
before calling any function ['Fred', 'George']
after calling a ['Fred', 'George']
after calling b ['Fred', 'George', 'Bill']
Run Code Online (Sandbox Code Playgroud) 我是TDD的新手,到目前为止非常喜欢它(尽管这是一个调整过程).
但是,我正在努力研究如何测试应用程序的入口点.我所说的那个main(String... args)方法是一个类,它的唯一职责是从/向磁盘加载和保存属性文件等.
当我第一次做代码时,这似乎不是问题.我只是不会为那些方法/类编写测试.但是,当我必须在没有测试的情况下编写代码时,我应该如何遵循TDD流程?
换句话说,何时/如何编写入口点适合TDD开发过程?
我是TDD的新手并且我很想开始使用它,但每当我正在处理的测试用例需要一个尚不存在的类(作为输入或作为输出)时,我都会遇到冲击.
问题是我不知道是否创建没有任何功能的类(是否考虑未经测试的代码?),或者停止测试(当它是绿色时),并开始为这个新的非编写测试 - 现有的课程.
第二种方法似乎是递归的,可能会让我失去思路,而第一种方法创造了一个没有测试的新课程.
有没有第三种方法我没有想到,哪种更好?
我有一个方法,它返回一个Object我用作字符串数组的映射。
我的问题是我不知道如何使用泛型来定义返回值以实现类型安全。
我想添加一个新的接口或类来表示地图,但我想避免这种情况,因为它Object本身已经是一张地图。
下面是一些示例代码,应该可以说明问题:
getMap() : Object {
return {
1: [ 'a', 'b', 'c' ]
2: [ 'd', 'e' ],
3: [ ]
}
}
Run Code Online (Sandbox Code Playgroud)
我希望能够定义该方法的返回值,以便清楚它是String[]or的映射Array<String>,而无需实现人为添加的Map接口。
有什么想法吗 ?
unit-testing ×3
angularjs ×2
tdd ×2
class ×1
entry-point ×1
firefox ×1
jasmine ×1
javascript ×1
list ×1
methodology ×1
mocking ×1
python ×1
reference ×1
testing ×1
typescript ×1