Here is a describe example that you can run and see what happens. I must mention that I am not using Protractor, so additional considerations may arise regarding its specific capabilities.
describe('Done functionality', function(){ var echoInOneSecond = function(value){ console.log('creating promise for ', value); return new Promise(function(resolve, reject){ console.log('resolving with ', value); resolve(value); }); }; it('#1 this will untruly PASS', function(){ var p = echoInOneSecond('value #1'); p.then(function(value){ console.log('#1 expecting...and value is ', value); expect(value).toBe('value #1'); }); }); it('#2 this will NOT FAIL', function(){ var p = echoInOneSecond('value #2'); p.then(function(value){ console.log('#2 expecting... and value is ', value); expect(value).not.toBe('value #2'); }); }); it('3 = will truly FAIl', function(done){ var p = echoInOneSecond('value #3'); p.then(function(value){ console.log('#3 expecting... and value is ', value); expect(value).not.toBe('value #3'); done(); }); }); it('4 = this will truly PASS', function(done){ var p = echoInOneSecond('value #4'); p.then(function(value){ console.log('#4 expecting... and value is ', value); expect(value).toBe('value #4'); done(); }); }); });
when you start the test, you will notice the sequence: first promises # 1, # 2, # 3 will be created and resolved first. Please note that waiting for # 1 and # 2 will not start yet, since promises are resolved asynchronously.
Then, since test # 3 uses done , after creating promise # 3, the functions for then all previous promises are evaluated: you will see "# 1 waiting ..." and "# 2" waiting ... ", but jasmine does not care about that, because tests No. 1 and No. 2 have already been completed, and all that concerns their implementation: only after expectations No. 3 are made, and it really will fail, because jasmine really cares about everything that happens before it done done() .
And then you can observe the # 4 test of the normal flow - creating a promise, resolution, expectation, everything considered by jasmine, so the expectation will really pass.