' +
@@ -505,7 +465,7 @@ describe('Binder', function() {
});
it('ItShouldSelectTheCorrectRadioBox', inject(function($rootScope, $compile) {
- var element = $compile(
+ element = $compile(
'
' +
'
' +
'
' +
@@ -527,7 +487,7 @@ describe('Binder', function() {
}));
it('ItShouldRepeatOnHashes', inject(function($rootScope, $compile) {
- var element = $compile(
+ element = $compile(
'
')($rootScope);
@@ -541,7 +501,7 @@ describe('Binder', function() {
}));
it('ItShouldFireChangeListenersBeforeUpdate', inject(function($rootScope, $compile) {
- var element = $compile('
')($rootScope);
+ element = $compile('
')($rootScope);
$rootScope.name = '';
$rootScope.$watch('watched', 'name=123');
$rootScope.watched = 'change';
@@ -551,7 +511,7 @@ describe('Binder', function() {
}));
it('ItShouldHandleMultilineBindings', inject(function($rootScope, $compile) {
- var element = $compile('
{{\n 1 \n + \n 2 \n}}
')($rootScope);
+ element = $compile('
{{\n 1 \n + \n 2 \n}}
')($rootScope);
$rootScope.$apply();
expect(element.text()).toBe('3');
}));
diff --git a/test/ScenarioSpec.js b/test/ScenarioSpec.js
index 986e2121..2070d301 100644
--- a/test/ScenarioSpec.js
+++ b/test/ScenarioSpec.js
@@ -1,23 +1,30 @@
'use strict';
describe("ScenarioSpec: Compilation", function() {
+ var element;
+
+ afterEach(function() {
+ dealoc(element);
+ });
+
+
describe('compilation', function() {
it("should compile dom node and return scope", inject(function($rootScope, $compile) {
var node = jqLite('
{{b=a+1}}
')[0];
- $compile(node)($rootScope);
+ element = $compile(node)($rootScope);
$rootScope.$digest();
expect($rootScope.a).toEqual(1);
expect($rootScope.b).toEqual(2);
}));
it("should compile jQuery node and return scope", inject(function($rootScope, $compile) {
- var element = $compile(jqLite('
{{a=123}}
'))($rootScope);
+ element = $compile(jqLite('
{{a=123}}
'))($rootScope);
$rootScope.$digest();
expect(jqLite(element).text()).toEqual('123');
}));
it("should compile text node and return scope", inject(function($rootScope, $compile) {
- var element = $compile('
{{a=123}}
')($rootScope);
+ element = $compile('
{{a=123}}
')($rootScope);
$rootScope.$digest();
expect(jqLite(element).text()).toEqual('123');
}));
diff --git a/test/directivesSpec.js b/test/directivesSpec.js
index 5bd5f5bd..9dee4860 100644
--- a/test/directivesSpec.js
+++ b/test/directivesSpec.js
@@ -1,6 +1,16 @@
'use strict';
describe("directive", function() {
+ var element;
+
+ beforeEach(function() {
+ element = null;
+ });
+
+ afterEach(function() {
+ dealoc(element);
+ });
+
var $filterProvider, element;
@@ -19,7 +29,7 @@ describe("directive", function() {
describe('ng:bind', function() {
it('should set text', inject(function($rootScope, $compile) {
- var element = $compile('
')($rootScope);
+ element = $compile('
')($rootScope);
expect(element.text()).toEqual('');
$rootScope.a = 'misko';
$rootScope.$digest();
@@ -28,47 +38,40 @@ describe("directive", function() {
}));
it('should set text to blank if undefined', inject(function($rootScope, $compile) {
- var element = $compile('
')($rootScope);
+ element = $compile('
')($rootScope);
$rootScope.a = 'misko';
$rootScope.$digest();
expect(element.text()).toEqual('misko');
$rootScope.a = undefined;
$rootScope.$digest();
expect(element.text()).toEqual('');
+ $rootScope.a = null;
+ $rootScope.$digest();
+ expect(element.text()).toEqual('');
}));
it('should set html', inject(function($rootScope, $compile) {
- var element = $compile('
')($rootScope);
+ element = $compile('
')($rootScope);
$rootScope.html = '
hello
';
$rootScope.$digest();
expect(lowercase(element.html())).toEqual('
hello
');
}));
it('should set unsafe html', inject(function($rootScope, $compile) {
- var element = $compile('
')($rootScope);
+ element = $compile('
')($rootScope);
$rootScope.html = '
hello
';
$rootScope.$digest();
expect(lowercase(element.html())).toEqual('
hello
');
}));
- it('should set element element', inject(function($rootScope, $compile) {
- $filterProvider.register('myElement', valueFn(function() {
- return jqLite('
hello ');
- }));
- var element = $compile('
')($rootScope);
- $rootScope.$digest();
- expect(lowercase(element.html())).toEqual('
hello ');
- }));
-
-
it('should suppress rendering of falsy values', inject(function($rootScope, $compile) {
- var element = $compile('
{{ null }}{{ undefined }}{{ "" }}-{{ 0 }}{{ false }}
')($rootScope);
+ element = $compile('
{{ null }}{{ undefined }}{{ "" }}-{{ 0 }}{{ false }}
')($rootScope);
$rootScope.$digest();
expect(element.text()).toEqual('-0false');
}));
it('should render object as JSON ignore $$', inject(function($rootScope, $compile) {
- var element = $compile('
{{ {key:"value", $$key:"hide"} }}
')($rootScope);
+ element = $compile('
{{ {key:"value", $$key:"hide"} }}
')($rootScope);
$rootScope.$digest();
expect(fromJson(element.text())).toEqual({key:'value'});
}));
@@ -76,27 +79,15 @@ describe("directive", function() {
describe('ng:bind-template', function() {
it('should ng:bind-template', inject(function($rootScope, $compile) {
- var element = $compile('
')($rootScope);
+ element = $compile('
')($rootScope);
$rootScope.name = 'Misko';
$rootScope.$digest();
expect(element.hasClass('ng-binding')).toEqual(true);
expect(element.text()).toEqual('Hello Misko!');
}));
- it('should have $element set to current bind element', inject(function($rootScope, $compile) {
- var innerText;
- $filterProvider.register('myFilter', valueFn(function(text) {
- innerText = innerText || this.$element.text();
- return text;
- }));
- var element = $compile('
beforeINNER after
')($rootScope);
- $rootScope.$digest();
- expect(element.text()).toEqual("beforeHELLOafter");
- expect(innerText).toEqual('INNER');
- }));
-
it('should render object as JSON ignore $$', inject(function($rootScope, $compile) {
- var element = $compile('
{{ {key:"value", $$key:"hide"} }} ')($rootScope);
+ element = $compile('
{{ {key:"value", $$key:"hide"} }} ')($rootScope);
$rootScope.$digest();
expect(fromJson(element.text())).toEqual({key:'value'});
}));
@@ -105,39 +96,40 @@ describe("directive", function() {
describe('ng:bind-attr', function() {
it('should bind attributes', inject(function($rootScope, $compile) {
- var element = $compile('
')($rootScope);
+ element = $compile('
')($rootScope);
$rootScope.$digest();
expect(element.attr('src')).toEqual('http://localhost/mysrc');
expect(element.attr('alt')).toEqual('myalt');
}));
it('should not pretty print JSON in attributes', inject(function($rootScope, $compile) {
- var element = $compile('
')($rootScope);
+ element = $compile('
')($rootScope);
$rootScope.$digest();
expect(element.attr('alt')).toEqual('{"a":1}');
}));
- });
- it('should remove special attributes on false', inject(function($rootScope, $compile) {
- var element = $compile('
')($rootScope);
- var input = element[0];
- expect(input.disabled).toEqual(false);
- expect(input.readOnly).toEqual(false);
- expect(input.checked).toEqual(false);
-
- $rootScope.disabled = true;
- $rootScope.readonly = true;
- $rootScope.checked = true;
- $rootScope.$digest();
-
- expect(input.disabled).toEqual(true);
- expect(input.readOnly).toEqual(true);
- expect(input.checked).toEqual(true);
- }));
+ it('should remove special attributes on false', inject(function($rootScope, $compile) {
+ element = $compile('
')($rootScope);
+ var input = element[0];
+ expect(input.disabled).toEqual(false);
+ expect(input.readOnly).toEqual(false);
+ expect(input.checked).toEqual(false);
+
+ $rootScope.disabled = true;
+ $rootScope.readonly = true;
+ $rootScope.checked = true;
+ $rootScope.$digest();
+
+ expect(input.disabled).toEqual(true);
+ expect(input.readOnly).toEqual(true);
+ expect(input.checked).toEqual(true);
+ }));
+
+ });
describe('ng:click', function() {
it('should get called on a click', inject(function($rootScope, $compile) {
- var element = $compile('
')($rootScope);
+ element = $compile('
')($rootScope);
$rootScope.$digest();
expect($rootScope.clicked).toBeFalsy();
@@ -146,14 +138,12 @@ describe("directive", function() {
}));
it('should stop event propagation', inject(function($rootScope, $compile) {
- var element = $compile('
')($rootScope);
+ element = $compile('
')($rootScope);
$rootScope.$digest();
expect($rootScope.outer).not.toBeDefined();
expect($rootScope.inner).not.toBeDefined();
- var innerDiv = element.children()[0];
-
- browserTrigger(innerDiv, 'click');
+ browserTrigger(element.find('div'), 'click');
expect($rootScope.outer).not.toBeDefined();
expect($rootScope.inner).toEqual(true);
}));
@@ -162,7 +152,7 @@ describe("directive", function() {
describe('ng:submit', function() {
it('should get called on form submit', inject(function($rootScope, $compile) {
- var element = $compile('
')($rootScope);
$rootScope.$digest();
@@ -175,7 +165,7 @@ describe("directive", function() {
describe('ng:class', function() {
it('should add new and remove old classes dynamically', inject(function($rootScope, $compile) {
- var element = $compile('
')($rootScope);
+ element = $compile('
')($rootScope);
$rootScope.dynClass = 'A';
$rootScope.$digest();
expect(element.hasClass('existing')).toBe(true);
@@ -196,7 +186,7 @@ describe("directive", function() {
it('should support adding multiple classes via an array', inject(function($rootScope, $compile) {
- var element = $compile('
')($rootScope);
+ element = $compile('
')($rootScope);
$rootScope.$digest();
expect(element.hasClass('existing')).toBeTruthy();
expect(element.hasClass('A')).toBeTruthy();
@@ -227,7 +217,7 @@ describe("directive", function() {
it('should support adding multiple classes via a space delimited string', inject(function($rootScope, $compile) {
- var element = $compile('
')($rootScope);
+ element = $compile('
')($rootScope);
$rootScope.$digest();
expect(element.hasClass('existing')).toBeTruthy();
expect(element.hasClass('A')).toBeTruthy();
@@ -236,7 +226,7 @@ describe("directive", function() {
it('should preserve class added post compilation with pre-existing classes', inject(function($rootScope, $compile) {
- var element = $compile('
')($rootScope);
+ element = $compile('
')($rootScope);
$rootScope.dynClass = 'A';
$rootScope.$digest();
expect(element.hasClass('existing')).toBe(true);
@@ -253,7 +243,7 @@ describe("directive", function() {
it('should preserve class added post compilation without pre-existing classes"', inject(function($rootScope, $compile) {
- var element = $compile('
')($rootScope);
+ element = $compile('
')($rootScope);
$rootScope.dynClass = 'A';
$rootScope.$digest();
expect(element.hasClass('A')).toBe(true);
@@ -269,119 +259,116 @@ describe("directive", function() {
it('should preserve other classes with similar name"', inject(function($rootScope, $compile) {
- var element = $compile('
')($rootScope);
+ element = $compile('
')($rootScope);
$rootScope.dynCls = 'panel';
$rootScope.$digest();
$rootScope.dynCls = 'foo';
$rootScope.$digest();
- expect(element[0].className).toBe('ui-panel ui-selected ng-directive foo');
+ expect(element[0].className).toBe('ui-panel ui-selected foo');
}));
it('should not add duplicate classes', inject(function($rootScope, $compile) {
- var element = $compile('
')($rootScope);
+ element = $compile('
')($rootScope);
$rootScope.dynCls = 'panel';
$rootScope.$digest();
- expect(element[0].className).toBe('panel bar ng-directive');
+ expect(element[0].className).toBe('panel bar');
}));
it('should remove classes even if it was specified via class attribute', inject(function($rootScope, $compile) {
- var element = $compile('
')($rootScope);
+ element = $compile('
')($rootScope);
$rootScope.dynCls = 'panel';
$rootScope.$digest();
$rootScope.dynCls = 'window';
$rootScope.$digest();
- expect(element[0].className).toBe('bar ng-directive window');
+ expect(element[0].className).toBe('bar window');
}));
it('should remove classes even if they were added by another code', inject(function($rootScope, $compile) {
- var element = $compile('
')($rootScope);
+ element = $compile('
')($rootScope);
$rootScope.dynCls = 'foo';
$rootScope.$digest();
element.addClass('foo');
$rootScope.dynCls = '';
$rootScope.$digest();
- expect(element[0].className).toBe('ng-directive');
}));
it('should convert undefined and null values to an empty string', inject(function($rootScope, $compile) {
- var element = $compile('
')($rootScope);
+ element = $compile('
')($rootScope);
$rootScope.dynCls = [undefined, null];
$rootScope.$digest();
- expect(element[0].className).toBe('ng-directive');
}));
- });
- it('should ng:class odd/even', inject(function($rootScope, $compile) {
- var element = $compile('
')($rootScope);
- $rootScope.$digest();
- var e1 = jqLite(element[0].childNodes[1]);
- var e2 = jqLite(element[0].childNodes[2]);
- expect(e1.hasClass('existing')).toBeTruthy();
- expect(e1.hasClass('odd')).toBeTruthy();
- expect(e2.hasClass('existing')).toBeTruthy();
- expect(e2.hasClass('even')).toBeTruthy();
- }));
+ it('should ng:class odd/even', inject(function($rootScope, $compile) {
+ element = $compile('')($rootScope);
+ $rootScope.$digest();
+ var e1 = jqLite(element[0].childNodes[1]);
+ var e2 = jqLite(element[0].childNodes[2]);
+ expect(e1.hasClass('existing')).toBeTruthy();
+ expect(e1.hasClass('odd')).toBeTruthy();
+ expect(e2.hasClass('existing')).toBeTruthy();
+ expect(e2.hasClass('even')).toBeTruthy();
+ }));
- it('should allow both ng:class and ng:class-odd/even on the same element', inject(function($rootScope, $compile) {
- var element = $compile('' +
- ' ' +
- '')($rootScope);
- $rootScope.$apply();
- var e1 = jqLite(element[0].childNodes[1]);
- var e2 = jqLite(element[0].childNodes[2]);
-
- expect(e1.hasClass('plainClass')).toBeTruthy();
- expect(e1.hasClass('odd')).toBeTruthy();
- expect(e1.hasClass('even')).toBeFalsy();
- expect(e2.hasClass('plainClass')).toBeTruthy();
- expect(e2.hasClass('even')).toBeTruthy();
- expect(e2.hasClass('odd')).toBeFalsy();
- }));
+ it('should allow both ng:class and ng:class-odd/even on the same element', inject(function($rootScope, $compile) {
+ element = $compile('' +
+ ' ' +
+ '')($rootScope);
+ $rootScope.$apply();
+ var e1 = jqLite(element[0].childNodes[1]);
+ var e2 = jqLite(element[0].childNodes[2]);
+ expect(e1.hasClass('plainClass')).toBeTruthy();
+ expect(e1.hasClass('odd')).toBeTruthy();
+ expect(e1.hasClass('even')).toBeFalsy();
+ expect(e2.hasClass('plainClass')).toBeTruthy();
+ expect(e2.hasClass('even')).toBeTruthy();
+ expect(e2.hasClass('odd')).toBeFalsy();
+ }));
- it('should allow both ng:class and ng:class-odd/even with multiple classes', inject(function($rootScope, $compile) {
- var element = $compile('' +
- ' ' +
- '')($rootScope);
- $rootScope.$apply();
- var e1 = jqLite(element[0].childNodes[1]);
- var e2 = jqLite(element[0].childNodes[2]);
-
- expect(e1.hasClass('A')).toBeTruthy();
- expect(e1.hasClass('B')).toBeTruthy();
- expect(e1.hasClass('C')).toBeTruthy();
- expect(e1.hasClass('D')).toBeTruthy();
- expect(e1.hasClass('E')).toBeFalsy();
- expect(e1.hasClass('F')).toBeFalsy();
-
- expect(e2.hasClass('A')).toBeTruthy();
- expect(e2.hasClass('B')).toBeTruthy();
- expect(e2.hasClass('E')).toBeTruthy();
- expect(e2.hasClass('F')).toBeTruthy();
- expect(e2.hasClass('C')).toBeFalsy();
- expect(e2.hasClass('D')).toBeFalsy();
- }));
+ it('should allow both ng:class and ng:class-odd/even with multiple classes', inject(function($rootScope, $compile) {
+ element = $compile('' +
+ ' ' +
+ '')($rootScope);
+ $rootScope.$apply();
+ var e1 = jqLite(element[0].childNodes[1]);
+ var e2 = jqLite(element[0].childNodes[2]);
+
+ expect(e1.hasClass('A')).toBeTruthy();
+ expect(e1.hasClass('B')).toBeTruthy();
+ expect(e1.hasClass('C')).toBeTruthy();
+ expect(e1.hasClass('D')).toBeTruthy();
+ expect(e1.hasClass('E')).toBeFalsy();
+ expect(e1.hasClass('F')).toBeFalsy();
+
+ expect(e2.hasClass('A')).toBeTruthy();
+ expect(e2.hasClass('B')).toBeTruthy();
+ expect(e2.hasClass('E')).toBeTruthy();
+ expect(e2.hasClass('F')).toBeTruthy();
+ expect(e2.hasClass('C')).toBeFalsy();
+ expect(e2.hasClass('D')).toBeFalsy();
+ }));
+ });
describe('ng:style', function() {
it('should set', inject(function($rootScope, $compile) {
- var element = $compile('
')($rootScope);
+ element = $compile('
')($rootScope);
$rootScope.$digest();
expect(element.css('height')).toEqual('40px');
}));
it('should silently ignore undefined style', inject(function($rootScope, $compile) {
- var element = $compile('
')($rootScope);
+ element = $compile('
')($rootScope);
$rootScope.$digest();
expect(element.hasClass('ng-exception')).toBeFalsy();
}));
@@ -454,8 +441,8 @@ describe("directive", function() {
describe('ng:show', function() {
it('should show and hide an element', inject(function($rootScope, $compile) {
- var element = jqLite('
');
- var element = $compile(element)($rootScope);
+ element = jqLite('
');
+ element = $compile(element)($rootScope);
$rootScope.$digest();
expect(isCssVisible(element)).toEqual(false);
$rootScope.exp = true;
@@ -465,8 +452,8 @@ describe("directive", function() {
it('should make hidden element visible', inject(function($rootScope, $compile) {
- var element = jqLite('
');
- var element = $compile(element)($rootScope);
+ element = jqLite('
');
+ element = $compile(element)($rootScope);
expect(isCssVisible(element)).toBe(false);
$rootScope.exp = true;
$rootScope.$digest();
@@ -476,8 +463,8 @@ describe("directive", function() {
describe('ng:hide', function() {
it('should hide an element', inject(function($rootScope, $compile) {
- var element = jqLite('
');
- var element = $compile(element)($rootScope);
+ element = jqLite('
');
+ element = $compile(element)($rootScope);
expect(isCssVisible(element)).toBe(true);
$rootScope.exp = true;
$rootScope.$digest();
@@ -552,7 +539,7 @@ describe("directive", function() {
describe('ng:cloak', function() {
it('should get removed when an element is compiled', inject(function($rootScope, $compile) {
- var element = jqLite('
');
+ element = jqLite('
');
expect(element.attr('ng:cloak')).toBe('');
$compile(element);
expect(element.attr('ng:cloak')).toBeUndefined();
@@ -560,7 +547,7 @@ describe("directive", function() {
it('should remove ng-cloak class from a compiled element', inject(function($rootScope, $compile) {
- var element = jqLite('
');
+ element = jqLite('
');
expect(element.hasClass('foo')).toBe(true);
expect(element.hasClass('ng-cloak')).toBe(true);
diff --git a/test/markupSpec.js b/test/markupSpec.js
index 0dcbbfe9..6f8e518e 100644
--- a/test/markupSpec.js
+++ b/test/markupSpec.js
@@ -1,33 +1,38 @@
'use strict';
describe("markups", function() {
+ var element;
+
+ afterEach(function() {
+ dealoc(element);
+ });
it('should translate {{}} in text', inject(function($rootScope, $compile) {
- var element = $compile('hello {{name}}!
')($rootScope)
- expect(sortedHtml(element)).toEqual('hello !
');
+ element = $compile('hello {{name}}!
')($rootScope)
+ $rootScope.$digest();
+ expect(sortedHtml(element)).toEqual('hello !
');
$rootScope.name = 'Misko';
$rootScope.$digest();
- expect(sortedHtml(element)).toEqual('hello Misko !
');
+ expect(sortedHtml(element)).toEqual('hello Misko!
');
}));
it('should translate {{}} in terminal nodes', inject(function($rootScope, $compile) {
- var element = $compile('Greet {{name}}! ')($rootScope)
+ element = $compile('Greet {{name}}! ')($rootScope)
$rootScope.$digest();
expect(sortedHtml(element).replace(' selected="true"', '')).
toEqual('' +
- 'Greet ! ' +
+ 'Greet ! ' +
' ');
$rootScope.name = 'Misko';
$rootScope.$digest();
expect(sortedHtml(element).replace(' selected="true"', '')).
toEqual('' +
- 'Greet Misko! ' +
+ 'Greet Misko! ' +
' ');
}));
it('should translate {{}} in attributes', inject(function($rootScope, $compile) {
- var element = $compile('
')($rootScope)
- expect(element.attr('ng:bind-attr')).toEqual('{"src":"http://server/{{path}}.png"}');
+ element = $compile('
')($rootScope)
$rootScope.path = 'a/b';
$rootScope.$digest();
expect(element.attr('src')).toEqual("http://server/a/b.png");
@@ -56,36 +61,38 @@ describe("markups", function() {
it('should populate value attribute on OPTION', inject(function($rootScope, $compile) {
- var element = $compile('abc ')($rootScope)
+ element = $compile('abc ')($rootScope)
expect(element).toHaveValue('abc');
}));
it('should ignore value if already exists', inject(function($rootScope, $compile) {
- var element = $compile('xyz ')($rootScope)
+ element = $compile('xyz ')($rootScope)
expect(element).toHaveValue('abc');
}));
it('should set value even if newlines present', inject(function($rootScope, $compile) {
- var element = $compile('\nabc\n ')($rootScope)
+ element = $compile('\nabc\n ')($rootScope)
expect(element).toHaveValue('\nabc\n');
}));
it('should set value even if self closing HTML', inject(function($rootScope, $compile) {
// IE removes the \n from option, which makes this test pointless
if (msie) return;
- var element = $compile('\n ')($rootScope)
+ element = $compile('\n ')($rootScope)
expect(element).toHaveValue('\n');
}));
});
it('should bind href', inject(function($rootScope, $compile) {
- var element = $compile(' ')($rootScope)
- expect(sortedHtml(element)).toEqual(' ');
+ element = $compile(' ')($rootScope)
+ $rootScope.url = 'http://server'
+ $rootScope.$digest();
+ expect(element.attr('href')).toEqual('http://server');
}));
it('should bind disabled', inject(function($rootScope, $compile) {
- var element = $compile('Button ')($rootScope)
+ element = $compile('Button ')($rootScope)
$rootScope.isDisabled = false;
$rootScope.$digest();
expect(element.attr('disabled')).toBeFalsy();
@@ -95,7 +102,7 @@ describe("markups", function() {
}));
it('should bind checked', inject(function($rootScope, $compile) {
- var element = $compile(' ')($rootScope)
+ element = $compile(' ')($rootScope)
$rootScope.isChecked = false;
$rootScope.$digest();
expect(element.attr('checked')).toBeFalsy();
@@ -105,7 +112,7 @@ describe("markups", function() {
}));
it('should bind selected', inject(function($rootScope, $compile) {
- var element = $compile('Greetings! ')($rootScope)
+ element = $compile('Greetings! ')($rootScope)
jqLite(document.body).append(element)
$rootScope.isSelected=false;
$rootScope.$digest();
@@ -116,7 +123,7 @@ describe("markups", function() {
}));
it('should bind readonly', inject(function($rootScope, $compile) {
- var element = $compile(' ')($rootScope)
+ element = $compile(' ')($rootScope)
$rootScope.isReadonly=false;
$rootScope.$digest();
expect(element.attr('readOnly')).toBeFalsy();
@@ -126,7 +133,7 @@ describe("markups", function() {
}));
it('should bind multiple', inject(function($rootScope, $compile) {
- var element = $compile(' ')($rootScope)
+ element = $compile(' ')($rootScope)
$rootScope.isMultiple=false;
$rootScope.$digest();
expect(element.attr('multiple')).toBeFalsy();
@@ -136,38 +143,37 @@ describe("markups", function() {
}));
it('should bind src', inject(function($rootScope, $compile) {
- var element = $compile('
')($rootScope)
+ element = $compile('
')($rootScope)
$rootScope.url = 'http://localhost/';
$rootScope.$digest();
expect(element.attr('src')).toEqual('http://localhost/');
}));
it('should bind href and merge with other attrs', inject(function($rootScope, $compile) {
- var element = $compile(' ')($rootScope)
- expect(sortedHtml(element)).toEqual(' ');
+ element = $compile(' ')($rootScope);
+ $rootScope.url = 'http://server';
+ $rootScope.rel = 'REL';
+ $rootScope.$digest();
+ expect(element.attr('href')).toEqual('http://server');
+ expect(element.attr('rel')).toEqual('REL');
}));
- it('should bind Text with no Bindings', inject(function($compile) {
- var $rootScope;
- function newScope (){
- return $rootScope = angular.injector(['ng']).get('$rootScope');
- }
+ it('should bind Text with no Bindings', inject(function($compile, $rootScope) {
forEach(['checked', 'disabled', 'multiple', 'readonly', 'selected'], function(name) {
- var element = $compile('
')(newScope())
- expect(element.attr('ng:bind-attr')).toBe('{"' + name +'":"some"}');
+ element = $compile('
')($rootScope)
$rootScope.$digest();
expect(element.attr(name)).toBe(name);
dealoc(element);
});
- var element = $compile('
')(newScope())
+ element = $compile('
')($rootScope)
$rootScope.$digest();
- expect(sortedHtml(element)).toEqual('
');
+ expect(element.attr('src')).toEqual('some');
dealoc(element);
- var element = $compile('
')(newScope())
+ element = $compile('
')($rootScope)
$rootScope.$digest();
- expect(sortedHtml(element)).toEqual('
');
+ expect(element.attr('href')).toEqual('some');
dealoc(element);
}));
});
diff --git a/test/sanitizerSpec.js b/test/sanitizerSpec.js
index 7467a833..a33d8992 100644
--- a/test/sanitizerSpec.js
+++ b/test/sanitizerSpec.js
@@ -2,9 +2,13 @@
describe('HTML', function() {
- function expectHTML(html) {
- return expect(new HTML(html).get());
- }
+ var expectHTML;
+
+ beforeEach(inject(function($sanitize) {
+ expectHTML = function(html){
+ return expect($sanitize(html));
+ };
+ }));
describe('htmlParser', function() {
var handler, start, text;
diff --git a/test/scenario/dslSpec.js b/test/scenario/dslSpec.js
index 79d479bb..c757d8a4 100644
--- a/test/scenario/dslSpec.js
+++ b/test/scenario/dslSpec.js
@@ -1,8 +1,13 @@
'use strict';
describe("angular.scenario.dsl", function() {
+ var element;
var $window, $root;
- var application, eventLog;
+ var eventLog;
+
+ afterEach(function() {
+ dealoc(element);
+ });
beforeEach(inject(function($injector) {
eventLog = [];
@@ -393,28 +398,26 @@ describe("angular.scenario.dsl", function() {
describe('Repeater', function() {
var chain;
- beforeEach(function() {
- doc.append(
- '' +
- ' misko ' +
- ' male ' +
- ' felisa ' +
- ' female ' +
- ' '
- );
+ beforeEach(inject(function($compile, $rootScope) {
+ element = $compile(
+ '')($rootScope);
+ $rootScope.items = [{name:'misko', gender:'male'}, {name:'felisa', gender:'female'}];
+ $rootScope.$apply();
+ doc.append(element);
chain = $root.dsl.repeater('ul li');
- });
+ }));
it('should get the row count', function() {
chain.count();
expect($root.futureResult).toEqual(2);
});
- it('should return 0 if repeater doesnt match', function() {
- doc.find('ul').html('');
+ it('should return 0 if repeater doesnt match', inject(function($rootScope) {
+ $rootScope.items = [];
+ $rootScope.$apply();
chain.count();
expect($root.futureResult).toEqual(0);
- });
+ }));
it('should get a row of bindings', function() {
chain.row(1);
@@ -422,7 +425,7 @@ describe("angular.scenario.dsl", function() {
});
it('should get a column of bindings', function() {
- chain.column('gender');
+ chain.column('i.gender');
expect($root.futureResult).toEqual(['male', 'female']);
});
@@ -437,45 +440,60 @@ describe("angular.scenario.dsl", function() {
});
describe('Binding', function() {
- it('should select binding by name', function() {
- doc.append('some value ');
+ var compile;
+
+ beforeEach(inject(function($compile, $rootScope) {
+ compile = function(html, value) {
+ element = $compile(html)($rootScope);
+ doc.append(element);
+ $rootScope.foo = {bar: value || 'some value'};
+ $rootScope.$apply();
+ };
+ }));
+
+
+ it('should select binding in interpolation', function() {
+ compile('{{ foo.bar }} ');
$root.dsl.binding('foo.bar');
expect($root.futureResult).toEqual('some value');
});
- it('should select binding by regexp', function() {
- doc.append('some value ');
- $root.dsl.binding(/^foo\..+/);
+ it('should select binding in multiple interpolations', function() {
+ compile('{{ foo.bar }} {{ true }} ');
+ $root.dsl.binding('foo.bar');
expect($root.futureResult).toEqual('some value');
+
+ $root.dsl.binding('true');
+ expect($root.futureResult).toEqual('true');
});
- it('should return value for input elements', function() {
- doc.append(' ');
+ it('should select binding by name', function() {
+ compile(' ');
$root.dsl.binding('foo.bar');
expect($root.futureResult).toEqual('some value');
});
- it('should return value for textarea elements', function() {
- doc.append('');
- $root.dsl.binding('foo.bar');
+ it('should select binding by regexp', function() {
+ compile('some value ');
+ $root.dsl.binding(/^foo\..+/);
expect($root.futureResult).toEqual('some value');
});
it('should return innerHTML for all the other elements', function() {
- doc.append('some value
');
+ compile('
', 'some value ');
$root.dsl.binding('foo.bar');
expect($root.futureResult.toLowerCase()).toEqual('some value ');
});
it('should select binding in template by name', function() {
- doc.append(' foo some baz ');
- $root.dsl.binding('bar');
- expect($root.futureResult).toEqual('foo some baz');
+ compile('
', 'bar');
+ $root.dsl.binding('foo.bar');
+ expect($root.futureResult).toEqual('bar');
});
it('should match bindings by substring match', function() {
- doc.append('
binding value ');
- $root.dsl.binding('test.baz');
+ compile('
', 'binding value');
+ $root.dsl.binding('foo . bar');
expect($root.futureResult).toEqual('binding value');
});
@@ -485,7 +503,7 @@ describe("angular.scenario.dsl", function() {
});
it('should return error if no binding matches', function() {
- doc.append('
some value ');
+ compile('
some value ');
$root.dsl.binding('foo.bar');
expect($root.futureError).toMatch(/did not match/);
});
diff --git a/test/service/filter/filtersSpec.js b/test/service/filter/filtersSpec.js
index cc006447..98651c58 100644
--- a/test/service/filter/filtersSpec.js
+++ b/test/service/filter/filtersSpec.js
@@ -153,14 +153,6 @@ describe('filters', function() {
});
});
- describe('html', function() {
- it('should do basic filter', function() {
- var html = filter('html')("a
c d");
- expect(html instanceof HTML).toBeTruthy();
- expect(html.html).toEqual("a
c d");
- });
- });
-
describe('linky', function() {
var linky;
@@ -169,7 +161,7 @@ describe('filters', function() {
}));
it('should do basic filter', function() {
- expect(linky("http://ab/ (http://a/)
http://1.2/v:~-123. c").html).
+ expect(linky("http://ab/ (http://a/)
http://1.2/v:~-123. c")).
toEqual('
http://ab/ ' +
'(
http://a/ ) ' +
'<
http://a/ > ' +
@@ -178,11 +170,11 @@ describe('filters', function() {
});
it('should handle mailto:', function() {
- expect(linky("mailto:me@example.com").html).
+ expect(linky("mailto:me@example.com")).
toEqual('
me@example.com ');
- expect(linky("me@example.com").html).
+ expect(linky("me@example.com")).
toEqual('
me@example.com ');
- expect(linky("send email to me@example.com, but").html).
+ expect(linky("send email to me@example.com, but")).
toEqual('send email to
me@example.com , but');
});
});
diff --git a/test/service/logSpec.js b/test/service/logSpec.js
index 98158ae0..df2bc933 100644
--- a/test/service/logSpec.js
+++ b/test/service/logSpec.js
@@ -69,7 +69,7 @@ describe('$log', function() {
e.stack = undefined;
$log = new $LogProvider().$get[1]({console:{error:function() {
- errorArgs = arguments;
+ errorArgs = [].slice.call(arguments, 0);
}}});
});
diff --git a/test/testabilityPatch.js b/test/testabilityPatch.js
index 85c844cb..1b4f11ba 100644
--- a/test/testabilityPatch.js
+++ b/test/testabilityPatch.js
@@ -61,9 +61,19 @@ afterEach(function() {
function dealoc(obj) {
if (obj) {
- var element = obj.$element || obj || {};
- if (element.nodeName) element = jqLite(element);
- if (element.dealoc) element.dealoc();
+ if (isElement(obj)) {
+ var element = obj;
+ if (element.nodeName) element = jqLite(element);
+ if (element.dealoc) element.dealoc();
+ } else {
+ for(var key in jqCache) {
+ var value = jqCache[key];
+ if (value.$scope == obj) {
+ delete jqCache[key];
+ }
+ }
+ }
+
}
}
diff --git a/test/widget/inputSpec.js b/test/widget/inputSpec.js
index 3e073d95..3b3aa282 100644
--- a/test/widget/inputSpec.js
+++ b/test/widget/inputSpec.js
@@ -51,7 +51,6 @@ describe('widget: input', function() {
it('should bind update scope from model', function() {
createInput();
- expect(scope.form.name.$required).toBe(false);
scope.name = 'misko';
scope.$digest();
expect(inputElement.val()).toEqual('misko');
@@ -60,7 +59,6 @@ describe('widget: input', function() {
it('should require', function() {
createInput({required:''});
- expect(scope.form.name.$required).toBe(true);
scope.$digest();
expect(scope.form.name.$valid).toBe(false);
scope.name = 'misko';
@@ -159,7 +157,7 @@ describe('widget: input', function() {
'
');
scope.obj = { abc: { name: 'Misko'} };
scope.$digest();
- expect(scope.$element.find('input').val()).toEqual('Misko');
+ expect(element.find('input').val()).toEqual('Misko');
});
@@ -181,7 +179,7 @@ describe('widget: input', function() {
it("should render as blank if null", function() {
compile('
');
expect(scope.age).toBeNull();
- expect(scope.$element[0].value).toEqual('');
+ expect(element[0].value).toEqual('');
});
@@ -189,19 +187,19 @@ describe('widget: input', function() {
compile('
');
scope.age = 123;
scope.$digest();
- expect(scope.$element.val()).toEqual('123');
+ expect(element.val()).toEqual('123');
try {
// to allow non-number values, we have to change type so that
// the browser which have number validation will not interfere with
// this test. IE8 won't allow it hence the catch.
- scope.$element[0].setAttribute('type', 'text');
+ element[0].setAttribute('type', 'text');
} catch (e){}
- scope.$element.val('123X');
- browserTrigger(scope.$element, 'change');
+ element.val('123X');
+ browserTrigger(element, 'change');
defer.flush();
- expect(scope.$element.val()).toEqual('123X');
+ expect(element.val()).toEqual('123X');
expect(scope.age).toEqual(123);
- expect(scope.$element).toBeInvalid();
+ expect(element).toBeInvalid();
});
@@ -211,28 +209,28 @@ describe('widget: input', function() {
// the user from ever typying ','.
compile('
');
- scope.$element.val('a ');
- browserTrigger(scope.$element, 'change');
+ element.val('a ');
+ browserTrigger(element, 'change');
defer.flush();
- expect(scope.$element.val()).toEqual('a ');
+ expect(element.val()).toEqual('a ');
expect(scope.list).toEqual(['a']);
- scope.$element.val('a ,');
- browserTrigger(scope.$element, 'change');
+ element.val('a ,');
+ browserTrigger(element, 'change');
defer.flush();
- expect(scope.$element.val()).toEqual('a ,');
+ expect(element.val()).toEqual('a ,');
expect(scope.list).toEqual(['a']);
- scope.$element.val('a , ');
- browserTrigger(scope.$element, 'change');
+ element.val('a , ');
+ browserTrigger(element, 'change');
defer.flush();
- expect(scope.$element.val()).toEqual('a , ');
+ expect(element.val()).toEqual('a , ');
expect(scope.list).toEqual(['a']);
- scope.$element.val('a , b');
- browserTrigger(scope.$element, 'change');
+ element.val('a , b');
+ browserTrigger(element, 'change');
defer.flush();
- expect(scope.$element.val()).toEqual('a , b');
+ expect(element.val()).toEqual('a , b');
expect(scope.list).toEqual(['a', 'b']);
});
@@ -240,7 +238,7 @@ describe('widget: input', function() {
it("should come up blank when no value specified", function() {
compile('
');
scope.$digest();
- expect(scope.$element.val()).toEqual('');
+ expect(element.val()).toEqual('');
expect(scope.age).toEqual(null);
});
});
@@ -250,7 +248,7 @@ describe('widget: input', function() {
it("should format booleans", function() {
compile('
');
expect(scope.name).toBe(false);
- expect(scope.$element[0].checked).toBe(false);
+ expect(element[0].checked).toBe(false);
});
@@ -270,15 +268,15 @@ describe('widget: input', function() {
scope.name='y';
scope.$digest();
- expect(scope.$element[0].checked).toBe(true);
+ expect(element[0].checked).toBe(true);
scope.name='n';
scope.$digest();
- expect(scope.$element[0].checked).toBe(false);
+ expect(element[0].checked).toBe(false);
scope.name='abc';
scope.$digest();
- expect(scope.$element[0].checked).toBe(false);
+ expect(element[0].checked).toBe(false);
browserTrigger(element);
expect(scope.name).toEqual('y');
@@ -302,7 +300,6 @@ describe('widget: input', function() {
it("should process required", inject(function($formFactory) {
compile('
', jqLite(document.body));
- expect($formFactory.rootForm.p.$required).toBe(true);
expect(element.hasClass('ng-invalid')).toBeTruthy();
scope.price = 'xxx';
@@ -394,7 +391,7 @@ describe('widget: input', function() {
'