Disable visibility behaviors when testing

It results in surprise behaviors.
This commit is contained in:
Michael Lange 2018-05-12 20:00:34 -07:00
parent 3f781743e4
commit 536c013928
2 changed files with 16 additions and 6 deletions

View file

@ -1,3 +1,4 @@
import Ember from 'ember';
import Mixin from '@ember/object/mixin'; import Mixin from '@ember/object/mixin';
import { assert } from '@ember/debug'; import { assert } from '@ember/debug';
@ -7,11 +8,15 @@ export default Mixin.create({
}, },
setupDocumentVisibility: function() { setupDocumentVisibility: function() {
if (!Ember.testing) {
this.set('_visibilityHandler', this.get('visibilityHandler').bind(this)); this.set('_visibilityHandler', this.get('visibilityHandler').bind(this));
document.addEventListener('visibilitychange', this.get('_visibilityHandler')); document.addEventListener('visibilitychange', this.get('_visibilityHandler'));
}
}.on('init'), }.on('init'),
removeDocumentVisibility: function() { removeDocumentVisibility: function() {
if (!Ember.testing) {
document.removeEventListener('visibilitychange', this.get('_visibilityHandler')); document.removeEventListener('visibilitychange', this.get('_visibilityHandler'));
}
}.on('willDestroy'), }.on('willDestroy'),
}); });

View file

@ -1,3 +1,4 @@
import Ember from 'ember';
import Mixin from '@ember/object/mixin'; import Mixin from '@ember/object/mixin';
import { assert } from '@ember/debug'; import { assert } from '@ember/debug';
@ -7,11 +8,15 @@ export default Mixin.create({
}, },
setupDocumentVisibility: function() { setupDocumentVisibility: function() {
if (!Ember.testing) {
this.set('_visibilityHandler', this.get('visibilityHandler').bind(this)); this.set('_visibilityHandler', this.get('visibilityHandler').bind(this));
document.addEventListener('visibilitychange', this.get('_visibilityHandler')); document.addEventListener('visibilitychange', this.get('_visibilityHandler'));
}
}.on('activate'), }.on('activate'),
removeDocumentVisibility: function() { removeDocumentVisibility: function() {
if (!Ember.testing) {
document.removeEventListener('visibilitychange', this.get('_visibilityHandler')); document.removeEventListener('visibilitychange', this.get('_visibilityHandler'));
}
}.on('deactivate'), }.on('deactivate'),
}); });