Files
ionic-framework/config/lib/testutil.js
Andy Joslin 98e7e3df46 refactor($ionicLoading,$ionicPopup): factor out common code, add tests
Also fixes $ionicLoading flickering on ios7 in beta.1.
2014-04-08 13:35:02 -06:00

43 lines
1.1 KiB
JavaScript

/*
* Included by karma
* Usage: var result = TestUtil.unwrapPromise(promise);
*/
var TestUtil = {
unwrapPromise: function(value) {
var result;
inject(function($rootScope, $q) {
$q.when(value).then(function(data) {
result = data;
});
$rootScope.$apply();
});
return result;
},
createMockTimeout: function(shouldApply) {
var timeoutQueue = [];
function timeout(fn, delay) {
timeoutQueue.push({fn: fn, delay: delay});
}
timeout.queue = timeoutQueue;
timeout.expect = function(expectedDelay) {
if (timeoutQueue.length > 0) {
return {
process: function() {
var tick = timeoutQueue.shift();
if (angular.isDefined(expectedDelay)) {
expect(tick.delay).toEqual(expectedDelay);
}
tick.fn();
shouldApply && inject(function($rootScope) {
$rootScope.$apply();
});
}
};
} else {
expect('TimoutQueue empty. Expecting delay of ').toEqual(delay);
}
};
return timeout;
}
};