Issues with integrating Ember.JS integration using andThen and click helpers

I get odd results with Ember andThen and click test andThen . According to the Ember documentation:

the assistant andThen will wait for all previous asynchronous helpers to complete before moving forward.

However, I believe that this is not always the case. In the example below, there are 3 console.debug statements. I would expect them to be written in the order A → B → C. But I sequentially get this order: A → C → B. I can only get the expected ABC order when I use only one of the two clicks helpers. There are no event (action) listeners associated with the <div> element specified in clicks.

Can someone explain this unexpected behavior? Is there a mistake in using helpers? Or a bug with the Ember testing platform?

 andThen(function() { console.debug('mark A'); click('div:first'); // with just 1 click helper, debug order is ABC click('div:first'); // with this second click helper, debug order is ACB andThen(function() { console.debug('mark B'); }); }); andThen(function() { console.debug('mark C'); }); 

Edit :

Based on Kingpin2k's answer, I ended up working on the next solution to get the testing style I was looking for.

First, I created an asynchronous test helper called next . Secondly, I replaced all andThen helpers in my code with special next helpers. This allowed my code to work in the order I expected.

 // test-helper.js Ember.Test.registerAsyncHelper('next', function(app, fn) { fn(); }); // my-integration-test.js next(function() { console.debug('mark A'); click('div:first'); click('div:first'); next(function() { console.debug('mark B'); }); }); next(function() { console.debug('mark C'); }); 
+5
source share
2 answers

andThen is just syntactic sugar for lastPromiseEmberSawCreated.then , so it looks like this:

 lastPromiseEmberSawCreated.then(function(){ console.debug('mark A'); click('div:first'); // with just 1 click helper, debug order is ABC click('div:first'); // with this second click helper, debug order is ACB nextLastPromiseEmberSawCreated.then(function() { console.debug('mark B'); }); }); // the promise won't have changed in between these two `andThen` calls // because Ember had no cpu time, and you didn't make any additional calls lastPromiseEmberSawCreated.then(function(){ console.debug('mark C'); }); 
+5
source

It makes no sense to use andThen in tests that hopefully reduce confusion. You can rewrite your example (if this function is labeled async :

 console.debug('mark A'); await click('div:first'); await click('div:first'); console.debug('mark B'); console.debug('mark C'); 

Operations are performed in order.

0
source

Source: https://habr.com/ru/post/1201242/


All Articles