Skip to content

Commit

Permalink
CB-8711 wait for all callbacks before evaluating expectations
Browse files Browse the repository at this point in the history
  • Loading branch information
purplecabbage committed Mar 19, 2015
1 parent 579d070 commit 74ae2f8
Showing 1 changed file with 15 additions and 3 deletions.
18 changes: 15 additions & 3 deletions test/android/test.exec.js
Expand Up @@ -19,7 +19,7 @@
*
*/

describe('exec.processMessages', function () {
describe('android exec.processMessages', function () {
var cordova = require('cordova'),
exec = require('cordova/android/exec'),
nativeApiProvider = require('cordova/android/nativeapiprovider'),
Expand Down Expand Up @@ -127,13 +127,14 @@ describe('exec.processMessages', function () {
});

function performExecAndReturn(messages) {

nativeApi.exec.andCallFake(function(secret, service, action, callbackId, argsJson) {
return messages;
});

var winSpy = jasmine.createSpy('win');

exec(null, null, 'Service', 'action', []);
// note: sometimes we need to wait for multiple callbacks, this returns after one
// see 'should handle multiple messages' below
waitsFor(function() { return callbackSpy.wasCalled }, 200);
}

Expand Down Expand Up @@ -198,6 +199,12 @@ describe('exec.processMessages', function () {
var message2 = createCallbackMessage(true, true, 1, 'id', 'f');
var messages = message1 + message2;
performExecAndReturn(messages);

// need to wait for ALL the callbacks before we check our expects
waitsFor(function(){
return callbackSpy.calls.length > 1;
},200);

runs(function() {
expect(callbackSpy).toHaveBeenCalledWith('id', false, 3, ['foo'], false);
expect(callbackSpy).toHaveBeenCalledWith('id', true, 1, [false], true);
Expand Down Expand Up @@ -228,6 +235,11 @@ describe('exec.processMessages', function () {
}
});
performExecAndReturn(message1 + message2);
// need to wait for ALL the callbacks before we check our expects
waitsFor(function(){
return callbackSpy.calls.length > 2;
},200);

runs(function() {
expect(callbackSpy.argsForCall.length).toEqual(3);
expect(callbackSpy.argsForCall[0]).toEqual(['id', false, 3, ['call1'], false]);
Expand Down

0 comments on commit 74ae2f8

Please sign in to comment.