Skip to content

Commit 570fa51

Browse files
author
ychartois
committed
Modification of the $timout.cancel in clearTimout to allow e2e test. Start writing e2e tests but sadly they are not functionnals yet.
1 parent a72fcb4 commit 570fa51

6 files changed

Lines changed: 27 additions & 13 deletions

File tree

app/js/timer.js

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ angular.module('timer', [])
3131

3232
function resetTimeout() {
3333
if ($scope.timeoutId) {
34-
$timeout.cancel($scope.timeoutId);
34+
clearTimeout($scope.timeoutId);
3535
}
3636
}
3737

@@ -49,7 +49,7 @@ angular.module('timer', [])
4949

5050
$scope.stop = $element[0].stop = function () {
5151
$scope.stoppedTime = new Date();
52-
$timeout.cancel($scope.timeoutId);
52+
clearTimeout($scope.timeoutId);
5353
$scope.timeoutId = null;
5454
};
5555

@@ -80,6 +80,10 @@ angular.module('timer', [])
8080
tick();
8181
$scope.$apply();
8282
}, $scope.interval);
83+
// $scope.timeoutId = $timeout(function() {
84+
// tick();
85+
// //$scope.$apply();
86+
// }, $scope.interval);
8387

8488
$scope.$emit('timer-tick', {timeoutId: $scope.timeoutId, millis: $scope.millis});
8589
};

config/karma-e2e.conf.js

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -7,14 +7,14 @@ files = [
77
'test/e2e/**/*.js'
88
];
99

10-
autoWatch = false;
10+
autoWatch = true;
1111

12-
browsers = ['Chrome'];
12+
browsers = ['Firefox'];
1313

14-
singleRun = true;
14+
singleRun = false;
1515

1616
proxies = {
17-
'/': 'http://localhost:8000/'
17+
'/': 'http://localhost:8383/'
1818
};
1919

2020
junitReporter = {

examples.html

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -249,7 +249,7 @@ <h3>AngularJS - Polling Timers</h3>
249249
};
250250

251251
$scope.$on('timer-tick', function (event, args) {
252-
$scope.timerConsole += $scope.timerType + ' - event.name = '+ event.name + ', timeoutId = ' + args.timeoutId.$$timeoutId + ', millis = ' + args.millis +'\n';
252+
$scope.timerConsole += $scope.timerType + ' - event.name = '+ event.name + ', timeoutId = ' + args.timeoutId + ', millis = ' + args.millis +'\n';
253253
});
254254
}
255255

examples/angularjs-polling-timer.html

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@
2323
};
2424

2525
$scope.$on('timer-tick', function (event, args) {
26-
$scope.timerConsole += $scope.timerType + ' - event.name = '+ event.name + ', timeoutId = ' + args.timeoutId.$$timeoutId + ', millis = ' + args.millis +'\n';
26+
$scope.timerConsole += $scope.timerType + ' - event.name = '+ event.name + ', timeoutId = ' + args.timeoutId + ', millis = ' + args.millis +'\n';
2727
});
2828
}
2929

scripts/libpeerconnection.log

Whitespace-only changes.

test/e2e/scenarios.js

Lines changed: 15 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -5,13 +5,23 @@
55
describe('timer directive', function() {
66

77
beforeEach(function() {
8-
browser().navigateTo('../../index.html');
8+
browser().navigateTo('angular-timer/index.html');
99
});
1010

11-
it('Simple timer', function() {
12-
sleep(2);
13-
var basicExample = angular.element('#timer1');
14-
console.log('######## basicExample = ', basicExample.html());
11+
it('should stop when user click on stop button [Simple Timer]', function() {
12+
sleep(1);
13+
element('#basic-timer button:last-child').click();
14+
var oldValue = element('#basic-timer span').text();
15+
sleep(1);
16+
expect( element('#basic-timer span').text() ).toBe( oldValue );
17+
});
18+
19+
it('should be reset when user click on start button again [Simple Timer]', function() {
20+
sleep(1);
21+
var oldValue = element('#basic-timer span').text();
22+
element('#basic-timer button:nth-child(3)').click();
23+
element('#basic-timer button:last-child').click();
24+
expect( element('#basic-timer span').text() ).toBeLessThan( oldValue );
1525
});
1626

1727
});

0 commit comments

Comments
 (0)