angular.js/test/ScenarioSpec.js

65 lines
2.2 KiB
JavaScript
Raw Normal View History

2010-01-23 23:54:58 +00:00
describe("ScenarioSpec: Compilation", function(){
it("should compile dom node and return scope", function(){
var node = jqLite('<div ng-init="a=1">{{b=a+1}}</div>')[0];
2010-01-23 23:54:58 +00:00
var scope = angular.compile(node);
scope.$init();
2010-03-30 21:55:04 +00:00
expect(scope.a).toEqual(1);
expect(scope.b).toEqual(2);
2010-01-23 23:54:58 +00:00
});
2010-01-23 23:54:58 +00:00
it("should compile jQuery node and return scope", function(){
var scope = angular.compile(jqLite('<div>{{a=123}}</div>')).$init();
expect(jqLite(scope.$element).text()).toEqual('123');
2010-01-23 23:54:58 +00:00
});
it("should compile text node and return scope", function(){
var scope = angular.compile('<div>{{a=123}}</div>').$init();
expect(jqLite(scope.$element).text()).toEqual('123');
2010-01-23 23:54:58 +00:00
});
});
describe("ScenarioSpec: Scope", function(){
xit("should have set, get, eval, $init, updateView methods", function(){
var scope = angular.compile('<div>{{a}}</div>').$init();
scope.$eval("$invalidWidgets.push({})");
expect(scope.$set("a", 2)).toEqual(2);
expect(scope.$get("a")).toEqual(2);
expect(scope.$eval("a=3")).toEqual(3);
scope.$eval();
expect(scope.$eval("$invalidWidgets")).toEqual([]);
expect(jqLite(scope.$element).text()).toEqual('3');
2010-01-23 23:54:58 +00:00
});
xit("should have $ objects", function(){
2010-01-23 23:54:58 +00:00
var scope = angular.compile('<div></div>', {a:"b"});
expect(scope.$get('$anchor')).toBeDefined();
expect(scope.$get('$eval')).toBeDefined();
expect(scope.$get('$config')).toBeDefined();
expect(scope.$get('$config.a')).toEqual("b");
expect(scope.$get('$datastore')).toBeDefined();
2010-01-23 23:54:58 +00:00
});
});
xdescribe("ScenarioSpec: configuration", function(){
2010-01-23 23:54:58 +00:00
it("should take location object", function(){
var url = "http://server/#book=moby";
var onUrlChange;
var location = {
listen:function(fn){onUrlChange=fn;},
set:function(u){url = u;},
get:function(){return url;}
};
var scope = angular.compile("<div>{{$anchor}}</div>", {location:location});
var $anchor = scope.$get('$anchor');
2010-01-23 23:54:58 +00:00
expect($anchor.book).toBeUndefined();
expect(onUrlChange).toBeUndefined();
scope.$init();
2010-01-23 23:54:58 +00:00
expect($anchor.book).toEqual('moby');
expect(onUrlChange).toBeDefined();
url = "http://server/#book=none";
onUrlChange();
2010-01-23 23:54:58 +00:00
expect($anchor.book).toEqual('none');
});
});