Skip to content

Commit

Permalink
make alert protractor testable
Browse files Browse the repository at this point in the history
Basicall using the `$interval` module. More details: angular/protractor#169 (comment)
  • Loading branch information
vlajos committed Jul 21, 2015
1 parent 2332f14 commit 2e915f1
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 6 deletions.
5 changes: 3 additions & 2 deletions src/alert/alert.js
Original file line number Diff line number Diff line change
Expand Up @@ -19,12 +19,13 @@ angular.module('ui.bootstrap.alert', [])
};
})

.directive('dismissOnTimeout', ['$timeout', function($timeout) {
.directive('dismissOnTimeout', ['$interval', function($interval) {
return {
require: 'alert',
link: function(scope, element, attrs, alertCtrl) {
$timeout(function(){
var intervalCanceller = $interval(function() {
alertCtrl.close();
$interval.cancel(intervalCanceller);
}, parseInt(attrs.dismissOnTimeout, 10));
}
};
Expand Down
8 changes: 4 additions & 4 deletions src/alert/test/dismissOnTimeout.spec.js
Original file line number Diff line number Diff line change
@@ -1,21 +1,21 @@
describe('dismissOnTimeout', function () {

var scope, $compile, $timeout;
var scope, $compile, $interval;

beforeEach(module('ui.bootstrap.alert'));
beforeEach(module('template/alert/alert.html'));
beforeEach(inject(function ($rootScope, _$compile_, _$timeout_) {
beforeEach(inject(function ($rootScope, _$compile_, _$interval_) {
scope = $rootScope;
$compile = _$compile_;
$timeout = _$timeout_;
$interval = _$interval_;
}));

it('should close automatically if auto-dismiss is defined on the element', function () {
scope.removeAlert = jasmine.createSpy();
$compile('<alert close="removeAlert()" dismiss-on-timeout="500">Default alert!</alert>')(scope);
scope.$digest();

$timeout.flush();
$interval.flush();
expect(scope.removeAlert).toHaveBeenCalled();
});
});

0 comments on commit 2e915f1

Please sign in to comment.