Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Protractor $timeout workaround #47

Merged
merged 1 commit into from
Jul 23, 2017
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 3 additions & 3 deletions demo/javascripts/main.js
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ $.fn.putCursorAtEnd = function () {

// Demo controller
var app = angular.module('demoApp', ['ngFlash', 'ngAnimate']);
app.controller('FlashDemoCtrl', ['$rootScope', '$scope', 'Flash', '$timeout', function ($rootScope, $scope, Flash, $timeout) {
app.controller('FlashDemoCtrl', ['$rootScope', '$scope', 'Flash', '$interval', function ($rootScope, $scope, Flash, $interval) {
$scope.success = function () {
var message = '<strong>Well done!</strong> You successfully read this important alert message.';
Flash.create('success', message);
Expand Down Expand Up @@ -138,10 +138,10 @@ app.controller('FlashDemoCtrl', ['$rootScope', '$scope', 'Flash', '$timeout', fu
$('#newList').on('keypress', function (e) {
if ($(this).val() !== '') {
if (e.which == 13) {
$timeout(function () {
$interval(function () {
$scope.add();
return false;
}, 100);
}, 100, 1);
}
}
});
Expand Down
10 changes: 5 additions & 5 deletions dist/angular-flash.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion dist/angular-flash.js.map

Large diffs are not rendered by default.

4 changes: 2 additions & 2 deletions dist/angular-flash.min.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion dist/angular-flash.min.js.map

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

8 changes: 4 additions & 4 deletions src/angular-flash.js
Original file line number Diff line number Diff line change
Expand Up @@ -132,7 +132,7 @@ app.provider('Flash', function() {
this.setShowClose(true);
this.setTemplatePreset('bootstrap');

this.$get = ['$rootScope', '$timeout', function($rootScope, $timeout) {
this.$get = ['$rootScope', '$interval', function($rootScope, $interval) {
const dataFactory = {};
let counter = 0;

Expand Down Expand Up @@ -162,15 +162,15 @@ app.provider('Flash', function() {
}
$rootScope.flashes.push(flash);
if (flash.timeout) {
flash.timeoutObj = $timeout(function() {
flash.timeoutObj = $interval(function() {
$this.dismiss(flash.id);
}, flash.timeout);
}, flash.timeout, 1);
}
return flash.id;
};
dataFactory.pause = function(index) {
if ($rootScope.flashes[index].timeoutObj) {
$timeout.cancel($rootScope.flashes[index].timeoutObj);
$interval.cancel($rootScope.flashes[index].timeoutObj);
}
};
dataFactory.dismiss = function(id) {
Expand Down
8 changes: 4 additions & 4 deletions test/angular-flash_test.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
describe('Unit testing Angular Flash', function() {
var $compile,
$rootScope,
$timeout,
$interval,
node,
Flash;

Expand All @@ -10,11 +10,11 @@ describe('Unit testing Angular Flash', function() {

// Store references to $rootScope and $compile
// so they are available to all tests in this describe block
beforeEach(inject(function(_$compile_, _$rootScope_, _$timeout_, _Flash_) {
beforeEach(inject(function(_$compile_, _$rootScope_, _$interval_, _Flash_) {
// The injector unwraps the underscores (_) from around the parameter names when matching
$compile = _$compile_;
$rootScope = _$rootScope_;
$timeout = _$timeout_;
$interval = _$interval_;
Flash = _Flash_;
}));

Expand Down Expand Up @@ -79,7 +79,7 @@ describe('Unit testing Angular Flash', function() {
var contents = node.contents()[0];
expect(contents.querySelectorAll('.alert').length).toEqual(1);

$timeout.flush();
$interval.flush();
$rootScope.$digest();
expect(contents.querySelectorAll('.alert').length).toEqual(0);
});
Expand Down