From e46100f7097d9a8f174bdb9e15d4c6098395c3f2 Mon Sep 17 00:00:00 2001
From: Misko Hevery
Date: Fri, 24 May 2013 12:41:38 -0700
Subject: feat($compile): support multi-element directive
By appending directive-start and directive-end to a
directive it is now possible to have the directive
act on a group of elements.
It is now possible to iterate over multiple elements like so:
I get repeated
I also get repeated
---
test/ng/compileSpec.js | 125 +++++++++++++++++++++++++++++++++++++++++++++++++
1 file changed, 125 insertions(+)
(limited to 'test/ng/compileSpec.js')
diff --git a/test/ng/compileSpec.js b/test/ng/compileSpec.js
index bf3d0b77..95b2ab72 100755
--- a/test/ng/compileSpec.js
+++ b/test/ng/compileSpec.js
@@ -2718,4 +2718,129 @@ describe('$compile', function() {
expect(element.attr('test4')).toBe('Misko');
}));
});
+
+
+ describe('multi-element directive', function() {
+ it('should group on link function', inject(function($compile, $rootScope) {
+ $rootScope.show = false;
+ element = $compile(
+ '' +
+ '' +
+ '' +
+ '
')($rootScope);
+ $rootScope.$digest();
+ var spans = element.find('span');
+ expect(spans.eq(0).css('display')).toBe('none');
+ expect(spans.eq(1).css('display')).toBe('none');
+ }));
+
+
+ it('should group on compile function', inject(function($compile, $rootScope) {
+ $rootScope.show = false;
+ element = $compile(
+ '' +
+ '{{i}}A' +
+ '{{i}}B;' +
+ '
')($rootScope);
+ $rootScope.$digest();
+ expect(element.text()).toEqual('1A1B;2A2B;');
+ }));
+
+
+ it('should group on $root compile function', inject(function($compile, $rootScope) {
+ $rootScope.show = false;
+ element = $compile(
+ '' +
+ '{{i}}A' +
+ '{{i}}B;' +
+ '')($rootScope);
+ $rootScope.$digest();
+ element = jqLite(element[0].parentNode.childNodes); // reset because repeater is top level.
+ expect(element.text()).toEqual('1A1B;2A2B;');
+ }));
+
+
+ it('should group on nested groups', inject(function($compile, $rootScope) {
+ $rootScope.show = false;
+ element = $compile(
+ '' +
+ '{{i}}A
' +
+ '' +
+ '' +
+ '{{i}}B;
' +
+ '')($rootScope);
+ $rootScope.$digest();
+ element = jqLite(element[0].parentNode.childNodes); // reset because repeater is top level.
+ expect(element.text()).toEqual('1A..1B;2A..2B;');
+ }));
+
+
+ it('should group on nested groups', inject(function($compile, $rootScope) {
+ $rootScope.show = false;
+ element = $compile(
+ '' +
+ '{{i}}(
' +
+ '{{j}}-' +
+ '{{j}}' +
+ '){{i}};
' +
+ '')($rootScope);
+ $rootScope.$digest();
+ element = jqLite(element[0].parentNode.childNodes); // reset because repeater is top level.
+ expect(element.text()).toEqual('1(2-23-3)1;2(2-23-3)2;');
+ }));
+
+
+ it('should throw error if unterminated', function () {
+ module(function($compileProvider) {
+ $compileProvider.directive('foo', function() {
+ return {
+ };
+ });
+ });
+ inject(function($compile, $rootScope) {
+ expect(function() {
+ element = $compile(
+ '' +
+ '' +
+ '
');
+ }).toThrow("[NgErr51] Unterminated attribute, found 'foo-start' but no matching 'foo-end' found.");
+ });
+ });
+
+
+ it('should throw error if unterminated', function () {
+ module(function($compileProvider) {
+ $compileProvider.directive('foo', function() {
+ return {
+ };
+ });
+ });
+ inject(function($compile, $rootScope) {
+ expect(function() {
+ element = $compile(
+ '' +
+ '' +
+ '
');
+ }).toThrow("[NgErr51] Unterminated attribute, found 'foo-start' but no matching 'foo-end' found.");
+ });
+ });
+
+
+ it('should support data- and x- prefix', inject(function($compile, $rootScope) {
+ $rootScope.show = false;
+ element = $compile(
+ '' +
+ '' +
+ '' +
+ '' +
+ '' +
+ '
')($rootScope);
+ $rootScope.$digest();
+ var spans = element.find('span');
+ expect(spans.eq(0).css('display')).toBe('none');
+ expect(spans.eq(1).css('display')).toBe('none');
+ expect(spans.eq(2).css('display')).toBe('none');
+ expect(spans.eq(3).css('display')).toBe('none');
+ }));
+ });
});
--
cgit v1.2.3