Skip to content
This repository was archived by the owner on Apr 12, 2024. It is now read-only.

Commit 913729e

Browse files
committed
fix isssue where the jasmine currentSpec does not get updated and hence everything runs as last spec context.
1 parent fce48eb commit 913729e

File tree

3 files changed

+76
-122
lines changed

3 files changed

+76
-122
lines changed

src/services.js

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -189,3 +189,7 @@ angularService('$route', function(location, params){
189189
return $route;
190190
}, {inject: ['$location']});
191191

192+
angularService('$resource', function(browser){
193+
var resource = new ResourceFactory(bind(browser, browser.xhr));
194+
return bind(resource, resource.route);
195+
}, {inject: ['$browser']});

test/ResourceSpec.js

Lines changed: 0 additions & 58 deletions
Original file line numberDiff line numberDiff line change
@@ -1,61 +1,3 @@
1-
function MockXHR(){
2-
this.expectations = {
3-
'GET': {},
4-
'POST': {},
5-
'DELETE': {}
6-
};
7-
this.queue = [];
8-
}
9-
MockXHR.prototype = {
10-
method: function(verb, url, data, callback) {
11-
if (verb == 'POST')
12-
url += '|' + angular.toJson(data);
13-
var response = this.expectations[verb][url];
14-
if (!response)
15-
throw "No expectation for " + verb + " on '" + url + "'.";
16-
this.queue.push(function(){
17-
callback(response);
18-
});
19-
},
20-
21-
expectGET: function(url) {
22-
var self = this;
23-
return {
24-
respond: function(response){
25-
self.expectations.GET[url] = response;
26-
}
27-
};
28-
},
29-
30-
expectDELETE: function(url) {
31-
var self = this;
32-
return {
33-
respond: function(response){
34-
self.expectations.DELETE[url] = response;
35-
}
36-
};
37-
},
38-
39-
expectPOST: function(url) {
40-
var self = this;
41-
return {
42-
data: function(data){
43-
return {
44-
respond: function(response){
45-
self.expectations.POST[url + '|' + angular.toJson(data)] = response;
46-
}
47-
};
48-
}
49-
};
50-
},
51-
52-
flush: function(){
53-
while(this.queue.length) {
54-
this.queue.shift()();
55-
}
56-
}
57-
};
58-
591
describe("resource", function() {
602
var xhr, resource, CreditCard, callback;
613

test/servicesSpec.js

Lines changed: 72 additions & 64 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,17 @@
1-
describe("services", function(){
1+
describe("service", function(){
22
var scope;
33

44
beforeEach(function(){
55
scope = createScope(null, angularService, {});
66
});
77

8+
afterEach(function(){
9+
if (scope && scope.$element)
10+
scope.$element.remove();
11+
});
12+
13+
14+
815
it("should inject $window", function(){
916
expect(scope.$window).toEqual(window);
1017
});
@@ -82,75 +89,76 @@ describe("services", function(){
8289
});
8390

8491
});
85-
});
8692

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);
94100
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+
});
95113
});
96114

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+
});
115154
});
116-
});
117155

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();
132159
});
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');
155160
});
161+
156162
});
163+
164+

0 commit comments

Comments
 (0)