Skip to content

Commit 68952fa

Browse files
rbezemerlozjackson
authored andcommitted
Ability to disable clock to run Ember Acceptance tests (#7)
1 parent 1044542 commit 68952fa

File tree

3 files changed

+24
-1
lines changed

3 files changed

+24
-1
lines changed

README.md

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -46,3 +46,16 @@ property: Ember.computed('clock.hour', function () {
4646
// this will update every hour
4747
})
4848
```
49+
## Know Issues
50+
The clock service will break Ember acceptance tests, as it creates a continuous run loop to update the current time. To disable the runloop update your config/environment file with the following
51+
```js
52+
module.exports = function(environment) {
53+
//...
54+
if (environment === 'test') {
55+
//...
56+
ENV['ember-clock'] = {
57+
disabled: true
58+
}
59+
}
60+
}
61+
```

addon/services/clock.js

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ import { bool } from '@ember/object/computed';
66
import { run } from '@ember/runloop';
77
import Service from '@ember/service';
88

9+
910
/**
1011
## ClockService
1112
@@ -121,6 +122,9 @@ export default Service.extend({
121122
*/
122123
tick() {
123124
this.setTime();
125+
if(this.get('disabled')) {
126+
return;
127+
}
124128
this.set('nextTick', run.later(this, this.tick, 1000));
125129
},
126130

app/services/clock.js

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1,7 @@
1-
export { default } from 'ember-clock/services/clock';
1+
import ENV from '../config/environment';
2+
import Service from 'ember-clock/services/clock'
3+
4+
const isDisabled = ENV['ember-clock'] && ENV['ember-clock'].disabled;
5+
export default Service.extend({
6+
disabled: isDisabled
7+
})

0 commit comments

Comments
 (0)