From 7a4b48020688060debe9cb0f9c17615d7585cbe7 Mon Sep 17 00:00:00 2001
From: Misko Hevery
Date: Mon, 5 Apr 2010 11:46:53 -0700
Subject: added ng:switch widget
---
test/BinderTest.js | 15 ---------------
test/ScenarioSpec.js | 12 ++++++------
test/ScopeSpec.js | 2 +-
test/ValidatorsTest.js | 2 +-
test/angular-mocks.js | 26 ++++++++++++++++++++++++++
test/servicesSpec.js | 8 ++++----
test/testabilityPatch.js | 40 ----------------------------------------
test/widgetsSpec.js | 16 ++++++++++++++++
8 files changed, 54 insertions(+), 67 deletions(-)
create mode 100644 test/angular-mocks.js
(limited to 'test')
diff --git a/test/BinderTest.js b/test/BinderTest.js
index fa3127d7..660ad78c 100644
--- a/test/BinderTest.js
+++ b/test/BinderTest.js
@@ -629,21 +629,6 @@ BinderTest.prototype.testDeleteAttributeIfEvaluatesFalse = function() {
assertChild(5, false);
};
-BinderTest.prototype.testRepeaterErrorShouldBePlacedOnInstanceNotOnTemplateComment = function () {
- var c = this.compile(
- '');
- c.scope.$eval();
- assertTrue(c.node.hasClass("ng-exception"));
-};
-
-BinderTest.prototype.testItShouldApplyAttributesBeforeTheWidgetsAreMaterialized = function() {
- var c = this.compile(
- '');
- c.scope.$set('person', {a:'misko', b:'adam'});
- c.scope.$eval();
- assertEquals("", c.node.html());
-};
-
BinderTest.prototype.XtestItShouldCallListenersWhenAnchorChanges = function() {
var log = "";
var c = this.compile('
');
diff --git a/test/ScenarioSpec.js b/test/ScenarioSpec.js
index 5b88a175..ff3a55b5 100644
--- a/test/ScenarioSpec.js
+++ b/test/ScenarioSpec.js
@@ -1,26 +1,26 @@
describe("ScenarioSpec: Compilation", function(){
it("should compile dom node and return scope", function(){
var node = jqLite('
{{b=a+1}}
')[0];
- var scope = angular.compile(node);
+ var scope = compile(node);
scope.$init();
expect(scope.a).toEqual(1);
expect(scope.b).toEqual(2);
});
it("should compile jQuery node and return scope", function(){
- var scope = angular.compile(jqLite('
{{a=123}}
')).$init();
+ var scope = compile(jqLite('
{{a=123}}
')).$init();
expect(jqLite(scope.$element).text()).toEqual('123');
});
it("should compile text node and return scope", function(){
- var scope = angular.compile('
{{a=123}}
').$init();
+ var scope = compile('
{{a=123}}
').$init();
expect(jqLite(scope.$element).text()).toEqual('123');
});
});
describe("ScenarioSpec: Scope", function(){
xit("should have set, get, eval, $init, updateView methods", function(){
- var scope = angular.compile('
{{a}}
').$init();
+ var scope = compile('
{{a}}
').$init();
scope.$eval("$invalidWidgets.push({})");
expect(scope.$set("a", 2)).toEqual(2);
expect(scope.$get("a")).toEqual(2);
@@ -31,7 +31,7 @@ describe("ScenarioSpec: Scope", function(){
});
xit("should have $ objects", function(){
- var scope = angular.compile('
', {a:"b"});
+ var scope = compile('
', {a:"b"});
expect(scope.$get('$anchor')).toBeDefined();
expect(scope.$get('$eval')).toBeDefined();
expect(scope.$get('$config')).toBeDefined();
@@ -49,7 +49,7 @@ xdescribe("ScenarioSpec: configuration", function(){
set:function(u){url = u;},
get:function(){return url;}
};
- var scope = angular.compile("
{{$anchor}}
", {location:location});
+ var scope = compile("
{{$anchor}}
", {location:location});
var $anchor = scope.$get('$anchor');
expect($anchor.book).toBeUndefined();
expect(onUrlChange).toBeUndefined();
diff --git a/test/ScopeSpec.js b/test/ScopeSpec.js
index a7322cae..09f4d875 100644
--- a/test/ScopeSpec.js
+++ b/test/ScopeSpec.js
@@ -44,7 +44,7 @@ describe('scope/model', function(){
model.$onEval(function(){evalCount ++;});
model.name = 'misko';
model.$eval();
- expect(nameCount).toEqual(1);
+ expect(nameCount).toEqual(2);
expect(evalCount).toEqual(1);
expect(model.newValue).toEqual('misko');
expect(model.oldValue).toEqual('adam');
diff --git a/test/ValidatorsTest.js b/test/ValidatorsTest.js
index 37be526d..d7da28cd 100644
--- a/test/ValidatorsTest.js
+++ b/test/ValidatorsTest.js
@@ -106,7 +106,7 @@ describe('Validator:asynchronous', function(){
it('should make a request and show spinner', function(){
var value, fn;
- var scope = angular.compile('
');
+ var scope = compile('
');
scope.$init();
var input = scope.$element;
scope.asyncFn = function(v,f){
diff --git a/test/angular-mocks.js b/test/angular-mocks.js
new file mode 100644
index 00000000..ab3638b1
--- /dev/null
+++ b/test/angular-mocks.js
@@ -0,0 +1,26 @@
+
+function MockBrowser() {
+ this.url = "http://server";
+ this.watches = [];
+}
+MockBrowser.prototype = {
+ xhr: function(method, url, callback) {
+
+ },
+
+ getUrl: function(){
+ return this.url;
+ },
+
+ setUrl: function(url){
+ this.url = url;
+ },
+
+ watchUrl: function(fn) {
+ this.watches.push(fn);
+ }
+};
+
+angular.service('$browser', function(){
+ return new MockBrowser();
+});
diff --git a/test/servicesSpec.js b/test/servicesSpec.js
index 193351d1..43511853 100644
--- a/test/servicesSpec.js
+++ b/test/servicesSpec.js
@@ -10,7 +10,7 @@ describe("services", function(){
});
it("should inject $location", function(){
- scope.$location('http://host:123/p/a/t/h.html?query=value#path?key=value');
+ scope.$location.parse('http://host:123/p/a/t/h.html?query=value#path?key=value');
expect(scope.$location.href).toEqual("http://host:123/p/a/t/h.html?query=value#path?key=value");
expect(scope.$location.protocol).toEqual("http");
expect(scope.$location.host).toEqual("host");
@@ -24,11 +24,11 @@ describe("services", function(){
scope.$location.hashPath = 'page=http://path';
scope.$location.hashSearch = {k:'a=b'};
- expect(scope.$location()).toEqual('http://host:123/p/a/t/h.html?query=value#page=http://path?k=a%3Db');
+ expect(scope.$location.toString()).toEqual('http://host:123/p/a/t/h.html?query=value#page=http://path?k=a%3Db');
});
it('should parse file://', function(){
- scope.$location('file:///Users/Shared/misko/work/angular.js/scenario/widgets.html');
+ scope.$location.parse('file:///Users/Shared/misko/work/angular.js/scenario/widgets.html');
expect(scope.$location.href).toEqual("file:///Users/Shared/misko/work/angular.js/scenario/widgets.html");
expect(scope.$location.protocol).toEqual("file");
expect(scope.$location.host).toEqual("");
@@ -39,7 +39,7 @@ describe("services", function(){
expect(scope.$location.hashPath).toEqual('');
expect(scope.$location.hashSearch).toEqual({});
- expect(scope.$location()).toEqual('file:///Users/Shared/misko/work/angular.js/scenario/widgets.html#');
+ expect(scope.$location.toString()).toEqual('file:///Users/Shared/misko/work/angular.js/scenario/widgets.html#');
});
xit('should add stylesheets', function(){
diff --git a/test/testabilityPatch.js b/test/testabilityPatch.js
index 752f8ef2..b2ee5526 100644
--- a/test/testabilityPatch.js
+++ b/test/testabilityPatch.js
@@ -5,46 +5,6 @@ function nakedExpect(obj) {
return expect(angular.fromJson(angular.toJson(obj)));
}
-swfobject = {
- createSwf:function() {
- fail("must mock out swfobject.createSwf in test.");
- }
-};
-
-function html(content) {
- return jQuery("
").html(content);
-}
-
-function report(reportTest){
- $("#tests").children().each(function(i){
- var success = this.className == "pass";
- var strong = this.firstChild;
- var msg = strong.firstChild.nodeValue;
- var parts = msg.split(" module: ");
- var module = parts[0];
- var name = parts[1].replace(/ *$/, "");
- reportTest(success, module, name, this.nodeValue);
- });
-}
-
-function MockBrowser() {
- this.url = "http://server";
- this.watches = [];
-}
-MockBrowser.prototype = {
- getUrl: function(){
- return this.url;
- },
-
- setUrl: function(url){
- this.url = url;
- },
-
- watchUrl: function(fn) {
- this.watches.push(fn);
- }
-};
-
angularService('$browser', function(){
return new MockBrowser();
});
diff --git a/test/widgetsSpec.js b/test/widgetsSpec.js
index a4afa21c..63c18700 100644
--- a/test/widgetsSpec.js
+++ b/test/widgetsSpec.js
@@ -188,5 +188,21 @@ describe("input widget", function(){
expect(element.hasClass('ng-exception')).toBeTruthy();
});
+ it('should switch on value change', function(){
+ compile('
first
second
');
+ expect(element.html()).toEqual('');
+ scope.select = 1;
+ scope.$eval();
+ expect(element.text()).toEqual('first');
+ scope.select = 2;
+ scope.$eval();
+ expect(element.text()).toEqual('second');
+ });
+});
+describe('ng:include', function(){
+ it('should include on external file', function() {
+ var element = jqLite('
');
+ var scope = compile(element).$init();
+ });
});
--
cgit v1.2.3