');
var log = '';
scope.$watch('$location.hash', function(){
log += this.$location.hashPath + ';';
@@ -259,7 +258,7 @@ describe("service", function(){
describe("$invalidWidgets", function(){
it("should count number of invalid widgets", function(){
- var scope = compile('
');
+ scope = compile('
');
jqLite(document.body).append(scope.$element);
scope.$init();
expect(scope.$invalidWidgets.length).toEqual(1);
@@ -291,8 +290,8 @@ describe("service", function(){
function BookChapter() {
this.log = '
';
}
- var scope = compile('').$init();
- var $route = scope.$inject('$route');
+ scope = compile('').$init();
+ $route = scope.$inject('$route');
$route.when('/Book/:book/Chapter/:chapter', {controller: BookChapter, template:'Chapter.html'});
$route.when('/Blank');
$route.onChange(function(){
diff --git a/test/testabilityPatch.js b/test/testabilityPatch.js
index e8041ac70fda..ea5c8ab71575 100644
--- a/test/testabilityPatch.js
+++ b/test/testabilityPatch.js
@@ -50,6 +50,25 @@ beforeEach(function(){
});
});
+afterEach(clearJqCache);
+
+function clearJqCache(){
+ var count = 0;
+ foreachSorted(jqCache, function(value, key){
+ count ++;
+ delete jqCache[key];
+ foreach(value, function(value, key){
+ if (value.$element)
+ dump(key, sortedHtml(value.$element));
+ else
+ dump(key, toJson(value));
+ });
+ });
+ if (count) {
+ fail('Found jqCache references that were not deallocated!');
+ }
+}
+
function nakedExpect(obj) {
return expect(angular.fromJson(angular.toJson(obj)));
}
@@ -58,6 +77,11 @@ function childNode(element, index) {
return jqLite(element[0].childNodes[index]);
}
+function dealoc(obj) {
+ var element = (obj||{}).$element || obj;
+ if (element && element.dealoc) element.dealoc();
+}
+
extend(angular, {
'element': jqLite,
'compile': compile,
diff --git a/test/widgetsSpec.js b/test/widgetsSpec.js
index d3957e667077..cb3b76a16666 100644
--- a/test/widgetsSpec.js
+++ b/test/widgetsSpec.js
@@ -16,8 +16,7 @@ describe("widget", function(){
});
afterEach(function(){
- if (element && element.dealoc) element.dealoc();
- expect(size(jqCache)).toEqual(0);
+ dealoc(element);
});
describe("input", function(){
@@ -362,7 +361,7 @@ describe("widget", function(){
'' +
'');
// childNodes[0] is repeater comment
- expect(scope.selection).toEqual(undefined);
+ expect(scope.selection).toEqual(0);
browserTrigger(element[0].childNodes[2], 'change');
expect(scope.selection).toEqual(1);
@@ -398,6 +397,32 @@ describe("widget", function(){
scope.$eval();
expect(element[0].childNodes[1].selected).toEqual(true);
});
+
+ it('should select default option on repeater', function(){
+ compile(
+ '');
+ expect(scope.selection).toEqual('1');
+ });
+
+ it('should select selected option on repeater', function(){
+ compile(
+ '');
+ expect(scope.selection).toEqual('ABC');
+ });
+
+ it('should select dynamically selected option on repeater', function(){
+ compile(
+ '');
+ expect(scope.selection).toEqual('2');
+ });
+
});
it('should support type="select-multiple"', function(){
@@ -476,6 +501,7 @@ describe("widget", function(){
scope.url = '/Book/Moby';
scope.$init();
expect(scope.$element.text()).toEqual('Moby');
+ dealoc(scope);
});
it("should match sandwich ids", function(){
@@ -491,6 +517,7 @@ describe("widget", function(){
scope.$init();
expect(scope.name).toEqual(undefined);
expect(scope.$element.text()).toEqual('works');
+ dealoc(scope);
});
});
@@ -504,6 +531,7 @@ describe("widget", function(){
scope.$inject('$xhr.cache').data.myUrl = {value:'{{name}}'};
scope.$init();
expect(element.text()).toEqual('misko');
+ dealoc(scope);
});
it('should remove previously included text if a falsy value is bound to src', function() {
@@ -521,6 +549,7 @@ describe("widget", function(){
scope.$eval();
expect(element.text()).toEqual('');
+ dealoc(scope);
});
it('should allow this for scope', function(){
@@ -532,6 +561,7 @@ describe("widget", function(){
// This should not be 4, but to fix this properly
// we need to have real events on the scopes.
expect(element.text()).toEqual('4');
+ dealoc(scope);
});
it('should evaluate onload expression when a partial is loaded', function() {
@@ -545,6 +575,7 @@ describe("widget", function(){
scope.$init();
expect(element.text()).toEqual('my partial');
expect(scope.loaded).toBe(true);
+ dealoc(scope);
});
});