')($rootScope);
$rootScope.$apply();
$httpBackend.flush();
expect(contentOnLink).toBe('someContent');
});
});
it('should add the content to the element before compiling it', function() {
var root;
module(function() {
directive('test', function() {
return {
link: function(scope, element) {
root = element.parent().parent();
}
};
});
});
inject(function($compile, $rootScope, $httpBackend) {
$httpBackend.expectGET('include.html').respond('
')($rootScope);
$rootScope.$apply();
$httpBackend.flush();
expect(root[0]).toBe(element[0]);
});
});
});
describe('and animations', function() {
var body, element, $rootElement;
function html(content) {
$rootElement.html(content);
element = $rootElement.children().eq(0);
return element;
}
beforeEach(module(function() {
// we need to run animation on attached elements;
return function(_$rootElement_) {
$rootElement = _$rootElement_;
body = jqLite(window.document.body);
body.append($rootElement);
};
}));
afterEach(function() {
dealoc(body);
dealoc(element);
});
beforeEach(module('ngAnimateMock'));
afterEach(function() {
dealoc(element);
});
it('should fire off the enter animation',
inject(function($compile, $rootScope, $templateCache, $animate) {
var item;
$templateCache.put('enter', [200, '
data
', {}]);
$rootScope.tpl = 'enter';
element = $compile(html(
'
'
))($rootScope);
$rootScope.$digest();
var animation = $animate.queue.pop();
expect(animation.event).toBe('enter');
expect(animation.element.text()).toBe('data');
})
);
it('should fire off the leave animation',
inject(function($compile, $rootScope, $templateCache, $animate) {
var item;
$templateCache.put('enter', [200, '
data
', {}]);
$rootScope.tpl = 'enter';
element = $compile(html(
'
'
))($rootScope);
$rootScope.$digest();
var animation = $animate.queue.shift();
expect(animation.event).toBe('enter');
expect(animation.element.text()).toBe('data');
$rootScope.tpl = '';
$rootScope.$digest();
animation = $animate.queue.shift();
expect(animation.event).toBe('leave');
expect(animation.element.text()).toBe('data');
})
);
it('should animate two separate ngInclude elements',
inject(function($compile, $rootScope, $templateCache, $animate) {
var item;
$templateCache.put('one', [200, 'one', {}]);
$templateCache.put('two', [200, 'two', {}]);
$rootScope.tpl = 'one';
element = $compile(html(
'
'
))($rootScope);
$rootScope.$digest();
var item1 = $animate.queue.shift().element;
expect(item1.text()).toBe('one');
$rootScope.tpl = 'two';
$rootScope.$digest();
var itemA = $animate.queue.shift().element;
var itemB = $animate.queue.shift().element;
expect(itemA.attr('ng-include')).toBe('tpl');
expect(itemB.attr('ng-include')).toBe('tpl');
expect(itemA).not.toEqual(itemB);
})
);
it('should destroy the previous leave animation if a new one takes place', function() {
module(function($provide) {
$provide.decorator('$animate', function($delegate, $$q) {
var emptyPromise = $$q.defer().promise;
emptyPromise.done = noop;
$delegate.leave = function() {
return emptyPromise;
};
return $delegate;
});
});
inject(function($compile, $rootScope, $animate, $templateCache) {
var item;
var $scope = $rootScope.$new();
element = $compile(html(
'
'
))($scope);
$templateCache.put('one', [200, '
one
', {}]);
$templateCache.put('two', [200, '
two
', {}]);
$scope.$apply('inc = "one"');
var destroyed, inner = element.children(0);
inner.on('$destroy', function() {
destroyed = true;
});
$scope.$apply('inc = "two"');
$scope.$apply('inc = "one"');
$scope.$apply('inc = "two"');
expect(destroyed).toBe(true);
});
});
});
});