|
1 |
| -describe("services", function(){ |
| 1 | +describe("service", function(){ |
2 | 2 | var scope;
|
3 | 3 |
|
4 | 4 | beforeEach(function(){
|
5 | 5 | scope = createScope(null, angularService, {});
|
6 | 6 | });
|
7 | 7 |
|
| 8 | + afterEach(function(){ |
| 9 | + if (scope && scope.$element) |
| 10 | + scope.$element.remove(); |
| 11 | + }); |
| 12 | + |
| 13 | + |
| 14 | + |
8 | 15 | it("should inject $window", function(){
|
9 | 16 | expect(scope.$window).toEqual(window);
|
10 | 17 | });
|
@@ -82,75 +89,76 @@ describe("services", function(){
|
82 | 89 | });
|
83 | 90 |
|
84 | 91 | });
|
85 |
| -}); |
86 | 92 |
|
87 |
| -describe("service $invalidWidgets", function(){ |
88 |
| - var scope; |
89 |
| - beforeEach(function(){ |
90 |
| - scope = null; |
91 |
| - }); |
92 |
| - afterEach(function(){ |
93 |
| - if (scope && scope.$element) |
| 93 | + describe("$invalidWidgets", function(){ |
| 94 | + it("should count number of invalid widgets", function(){ |
| 95 | + var scope = compile('<input name="price" ng-required ng-validate="number"></input>').$init(); |
| 96 | + expect(scope.$invalidWidgets.length).toEqual(1); |
| 97 | + scope.price = 123; |
| 98 | + scope.$eval(); |
| 99 | + expect(scope.$invalidWidgets.length).toEqual(0); |
94 | 100 | scope.$element.remove();
|
| 101 | + scope.price = 'abc'; |
| 102 | + scope.$eval(); |
| 103 | + expect(scope.$invalidWidgets.length).toEqual(1); |
| 104 | + |
| 105 | + jqLite(document.body).append(scope.$element); |
| 106 | + scope.$invalidWidgets.clearOrphans(); |
| 107 | + expect(scope.$invalidWidgets.length).toEqual(1); |
| 108 | + |
| 109 | + jqLite(document.body).html(''); |
| 110 | + scope.$invalidWidgets.clearOrphans(); |
| 111 | + expect(scope.$invalidWidgets.length).toEqual(0); |
| 112 | + }); |
95 | 113 | });
|
96 | 114 |
|
97 |
| - it("should count number of invalid widgets", function(){ |
98 |
| - var scope = compile('<input name="price" ng-required ng-validate="number"></input>').$init(); |
99 |
| - expect(scope.$invalidWidgets.length).toEqual(1); |
100 |
| - scope.price = 123; |
101 |
| - scope.$eval(); |
102 |
| - expect(scope.$invalidWidgets.length).toEqual(0); |
103 |
| - scope.$element.remove(); |
104 |
| - scope.price = 'abc'; |
105 |
| - scope.$eval(); |
106 |
| - expect(scope.$invalidWidgets.length).toEqual(1); |
107 |
| - |
108 |
| - jqLite(document.body).append(scope.$element); |
109 |
| - scope.$invalidWidgets.clearOrphans(); |
110 |
| - expect(scope.$invalidWidgets.length).toEqual(1); |
111 |
| - |
112 |
| - jqLite(document.body).html(''); |
113 |
| - scope.$invalidWidgets.clearOrphans(); |
114 |
| - expect(scope.$invalidWidgets.length).toEqual(0); |
| 115 | + |
| 116 | + describe("$route", function(){ |
| 117 | + it('should route and fire change event', function(){ |
| 118 | + var log = ''; |
| 119 | + function BookChapter() { |
| 120 | + this.log = '<init>'; |
| 121 | + } |
| 122 | + BookChapter.prototype.init = function(){ |
| 123 | + log += 'init();'; |
| 124 | + }; |
| 125 | + var scope = compile('<div></div>').$init(); |
| 126 | + scope.$route.when('/Book/:book/Chapter/:chapter', {controller: BookChapter, template:'Chapter.html'}); |
| 127 | + scope.$route.when('/Blank'); |
| 128 | + scope.$route.onChange(function(){ |
| 129 | + log += 'onChange();'; |
| 130 | + }); |
| 131 | + scope.$location.parse('http://server#/Book/Moby/Chapter/Intro?p=123'); |
| 132 | + scope.$eval(); |
| 133 | + expect(log).toEqual('onChange();init();'); |
| 134 | + expect(scope.$route.current.params).toEqual({book:'Moby', chapter:'Intro', p:'123'}); |
| 135 | + expect(scope.$route.current.scope.log).toEqual('<init>'); |
| 136 | + var lastId = scope.$route.current.scope.$id; |
| 137 | + |
| 138 | + log = ''; |
| 139 | + scope.$location.parse('http://server#/Blank?ignore'); |
| 140 | + scope.$eval(); |
| 141 | + expect(log).toEqual('onChange();'); |
| 142 | + expect(scope.$route.current.params).toEqual({ignore:true}); |
| 143 | + expect(scope.$route.current.scope.$id).not.toEqual(lastId); |
| 144 | + |
| 145 | + log = ''; |
| 146 | + scope.$location.parse('http://server#/NONE'); |
| 147 | + scope.$eval(); |
| 148 | + expect(log).toEqual('onChange();'); |
| 149 | + expect(scope.$route.current).toEqual(null); |
| 150 | + |
| 151 | + scope.$route.when('/NONE', {template:'instant update'}); |
| 152 | + expect(scope.$route.current.template).toEqual('instant update'); |
| 153 | + }); |
115 | 154 | });
|
116 |
| -}); |
117 | 155 |
|
118 |
| -describe("service $route", function(){ |
119 |
| - it('should route and fire change event', function(){ |
120 |
| - var log = ''; |
121 |
| - function BookChapter() { |
122 |
| - this.log = '<init>'; |
123 |
| - } |
124 |
| - BookChapter.prototype.init = function(){ |
125 |
| - log += 'init();'; |
126 |
| - }; |
127 |
| - var scope = compile('<div></div>').$init(); |
128 |
| - scope.$route.when('/Book/:book/Chapter/:chapter', {controller: BookChapter, template:'Chapter.html'}); |
129 |
| - scope.$route.when('/Blank'); |
130 |
| - scope.$route.onChange(function(){ |
131 |
| - log += 'onChange();'; |
| 156 | + describe('$resource', function(){ |
| 157 | + it('should publish to root scope', function(){ |
| 158 | + expect(scope.$resource).toBeTruthy(); |
132 | 159 | });
|
133 |
| - scope.$location.parse('http://server#/Book/Moby/Chapter/Intro?p=123'); |
134 |
| - scope.$eval(); |
135 |
| - expect(log).toEqual('onChange();init();'); |
136 |
| - expect(scope.$route.current.params).toEqual({book:'Moby', chapter:'Intro', p:'123'}); |
137 |
| - expect(scope.$route.current.scope.log).toEqual('<init>'); |
138 |
| - var lastId = scope.$route.current.scope.$id; |
139 |
| - |
140 |
| - log = ''; |
141 |
| - scope.$location.parse('http://server#/Blank?ignore'); |
142 |
| - scope.$eval(); |
143 |
| - expect(log).toEqual('onChange();'); |
144 |
| - expect(scope.$route.current.params).toEqual({ignore:true}); |
145 |
| - expect(scope.$route.current.scope.$id).not.toEqual(lastId); |
146 |
| - |
147 |
| - log = ''; |
148 |
| - scope.$location.parse('http://server#/NONE'); |
149 |
| - scope.$eval(); |
150 |
| - expect(log).toEqual('onChange();'); |
151 |
| - expect(scope.$route.current).toEqual(null); |
152 |
| - |
153 |
| - scope.$route.when('/NONE', {template:'instant update'}); |
154 |
| - expect(scope.$route.current.template).toEqual('instant update'); |
155 | 160 | });
|
| 161 | + |
156 | 162 | });
|
| 163 | + |
| 164 | + |
0 commit comments