在AngularJS中单元测试隔离范围的好方法是什么
指令片段
scope: {name: '=myGreet'},
link: function (scope, element, attrs) {
//show the initial state
greet(element, scope[attrs.myGreet]);
//listen for changes in the model
scope.$watch(attrs.myGreet, function (name) {
greet(element, name);
});
}
Run Code Online (Sandbox Code Playgroud)
我想,以确保指令监听的变化-这并不会与一个孤立的范围内工作:
it('should watch for changes in the model', function () {
var elm;
//arrange
spyOn(scope, '$watch');
//act
elm = compile(validHTML)(scope);
//assert
expect(scope.$watch.callCount).toBe(1);
expect(scope.$watch).toHaveBeenCalledWith('name', jasmine.any(Function));
});
Run Code Online (Sandbox Code Playgroud)
更新: 我通过检查预期观察者是否被添加到子范围来实现它,但它非常脆弱,并且可能以未记录的方式使用访问者(也可能更改,恕不另行通知!).
//this is super brittle, is there a better way!?
elm = compile(validHTML)(scope);
expect(elm.scope().$$watchers[0].exp).toBe('name');
Run Code Online (Sandbox Code Playgroud)
更新2:
正如我所说,这很脆弱!这个想法仍然有效,但在较新版本的AngularJS中,访问者已经从以下scope()
变为isolateScope()
: …
javascript unit-testing jasmine angularjs angularjs-directive
有没有人使用David Orchard的分叉用于PhoneGap的应用内购买?它在一年多来没有更新.根据这个线程, Urban Airship还无法帮助.
混合身份验证配置ASP.NET模块(MADAM)正是我在MVC2中构建的项目所需要的.我不是身份验证专家,MADAM可以快速改装以使用MVC管道吗?
http://msdn.microsoft.com/en-us/library/aa479391.aspx
我最近使用Dojo工具包构建了一个项目,并且喜欢如何将一段代码标记为仅基于任意条件检查包含在编译版本中.我用它来导出私有变量进行单元测试或抛出错误而不是记录它们.这是Dojo格式的一个例子,我很想知道Google Closure Compiler是否有这样的特殊指令.
window.module = (function(){
//private variable
var bar = {hidden:"secret"};
//>>excludeStart("DEBUG", true);
//export internal variables for unit testing
window.bar = bar;
//>>excludeEnd("DEBUG");
//return privileged methods
return {
foo: function(val){
bar.hidden = val;
}
};
})();
Run Code Online (Sandbox Code Playgroud)
编辑
关闭权威指南提到您可以扩展CommandLineRunner以添加您自己的检查和优化,这可能是一种方法.Plover看起来很有前途,因为它支持自定义传递.
它正在破坏我的单元测试的显示,是否有一个简单的方法来关闭它?
javascript ×3
unit-testing ×3
.net ×1
angularjs ×1
app-store ×1
asp.net ×1
asp.net-mvc ×1
c# ×1
command-line ×1
cordova ×1
iphone ×1
jasmine ×1
npm ×1
spinner ×1