I am trying to get some tests to pass for an ember addon. It was working fine until yesterday I added some code that runs later in the run loops using Em.run.next.
Here is what Im doing in my test.
visit('/').then(function() {
find('bm-select').click();
andThen(function() {
equal(1,1, 'yay');
});
});
The problem is when click is triggered, the later function is executed after andThen
. By that time all my tests are done and it throws error. I am under the impression andThen should wait for all async stuff to finish.
This is what what my code looks like when click is triggered(focusOut event is triggered 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 gives 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.$()
returns undefined.
I tried the wait
helper and still I am not able to get the tests to work. How is this normally done.
I have extracted the tests to run in a bin. Here is the link to it.