|
| 1 | +describe('ngTransclude', function() { |
| 2 | + |
| 3 | + beforeEach(function() { |
| 4 | + delete window.angular; |
| 5 | + publishExternalAPI(); |
| 6 | + }); |
| 7 | + |
| 8 | + function createInjectorWithTranscluderTemplate(template) { |
| 9 | + return createInjector(['ng', function($compileProvider) { |
| 10 | + $compileProvider.directive('myTranscluder', function() { |
| 11 | + return { |
| 12 | + transclude: true, |
| 13 | + template: template |
| 14 | + }; |
| 15 | + }); |
| 16 | + }]); |
| 17 | + } |
| 18 | + |
| 19 | + it('transcludes the parent directive transclusion', function() { |
| 20 | + var injector = createInjectorWithTranscluderTemplate( |
| 21 | + '<div ng-transclude></div>' |
| 22 | + ); |
| 23 | + injector.invoke(function($compile, $rootScope) { |
| 24 | + var el = $('<div my-transcluder>Hello</div>'); |
| 25 | + $compile(el)($rootScope); |
| 26 | + expect(el.find('> [ng-transclude]').html()).toEqual('Hello'); |
| 27 | + }); |
| 28 | + }); |
| 29 | + |
| 30 | + it('empties existing contents', function() { |
| 31 | + var injector = createInjectorWithTranscluderTemplate( |
| 32 | + '<div ng-transclude>Existing contents</div>' |
| 33 | + ); |
| 34 | + injector.invoke(function($compile, $rootScope) { |
| 35 | + var el = $('<div my-transcluder>Hello</div>'); |
| 36 | + $compile(el)($rootScope); |
| 37 | + expect(el.find('> [ng-transclude]').html()).toEqual('Hello'); |
| 38 | + }); |
| 39 | + }); |
| 40 | + |
| 41 | + it('may be used as element', function() { |
| 42 | + var injector = createInjectorWithTranscluderTemplate( |
| 43 | + '<ng-transclude>Existing contents</ng-transclude>' |
| 44 | + ); |
| 45 | + injector.invoke(function($compile, $rootScope) { |
| 46 | + var el = $('<div my-transcluder>Hello</div>'); |
| 47 | + $compile(el)($rootScope); |
| 48 | + expect(el.find('> ng-transclude').html()).toEqual('Hello'); |
| 49 | + }); |
| 50 | + }); |
| 51 | + |
| 52 | + it('may be used as class', function() { |
| 53 | + var injector = createInjectorWithTranscluderTemplate( |
| 54 | + '<div class="ng-transclude">Existing contents</div>' |
| 55 | + ); |
| 56 | + injector.invoke(function($compile, $rootScope) { |
| 57 | + var el = $('<div my-transcluder>Hello</div>'); |
| 58 | + $compile(el)($rootScope); |
| 59 | + expect(el.find('> .ng-transclude').html()).toEqual('Hello'); |
| 60 | + }); |
| 61 | + }); |
| 62 | + |
| 63 | +}); |
0 commit comments