Ending tests before running Ember.run.later
I am trying to pass tests for ember addon . It worked fine until yesterday, I added code that runs later in the startup loops using Em.run.next.
Here is what I am doing in my test.
visit('/').then(function() {
find('bm-select').click();
andThen(function() {
equal(1,1, 'yay');
});
});
The problem is when the click is fired, the later function is executed after andThen
. By this time, all my tests have completed and this is causing the error. This is my impression and I have to wait for all asynchronous things to finish.
This is what my code looks like when the button is clicked (the focusOut event is fired on click)
lostFocus: function() {
if(this.get('isOpen')) {
Em.run.later(this, function() {
var focussedElement = document.activeElement;
var isFocussedOut =
this.$().has(focussedElement).length === 0 && !this.$().is(focussedElement);
if(isFocussedOut) {
this.closeOptions({focus:false});
}
}, 0);
}
}.on('focusOut'),
You can see that it is giving an error Uncaught TypeError: Cannot read property 'has' of undefined
. This is from the focusOut method. By the time the function executes the components, _state is "destroying" and this.$()
returning undefined.
I tried the helper wait
and still I can't get the tests to work. How is it usually done. I have extracted the tests to run in the cart. Here is a link to it .
source to share
After further debugging, the problem is one of the "bm-select" tags has an event focusOut
triggered in the teardown test method. Thus, by the time the run loop code is executed, the component is not inDOM.
I just added a hidden input field in a test app. Once I ran all the tests, I focused on the hidden input field and used the test helper wait
. Now all of the startup loop code is executed by the time the break method is executed.
source to share