Fix tear down click handler problem in tests

It's not obvious what "the way" to teardown window event handlers is in
Ember. The datacenter-picker is permanently in the app during usage, but
in tests I'm assuming it gets added and removed lots.

So when you run the tests, as the tests aren't run in an isolated runner
the QUnit test runner ends up with a click handler on it, So if you
click on the test runner one of the tests will fail.

The failure is related to there not being an element with a `.contains`
method. So this checks that the element is truthy first, i.e. it exists.
If it doesn't it just bails out.
This commit is contained in:
John Cowen 2018-05-23 14:46:57 +01:00
parent 284f9bd33d
commit 47730f96ea
1 changed files with 7 additions and 3 deletions

View File

@ -3,9 +3,13 @@ import Mixin from '@ember/object/mixin';
import { next } from '@ember/runloop';
import { get } from '@ember/object';
const isOutside = function(element, e) {
const isRemoved = !e.target || !document.contains(e.target);
const isInside = element === e.target || element.contains(e.target);
return !isRemoved && !isInside;
if (element) {
const isRemoved = !e.target || !document.contains(e.target);
const isInside = element === e.target || element.contains(e.target);
return !isRemoved && !isInside;
} else {
return false;
}
};
const handler = function(e) {
const el = get(this, 'element');