So i tried to get the promises to work in my angular app tests, can anyone figure out what im doing wrong here it keeps returning:
Error: timeout of 2000ms exceeded. Ensure the done() callback is being called in this test.
I don't know if it's $q.
FYI i also tried the it('test', function(done){... done();})
Controller
(function() {
'use strict';
angular
.module('controller.editor', [])
.controller('EditorController', EditorController);
function EditorController($scope, $q) {
var vm = this;
angular.extend(vm, {
hack: hack
});
function hack(bool) {
return $q(function(resolve, reject) {
if (bool) {
resolve(true);
}
reject(false);
});
}
}
});
Test
describe('EditorController', function() {
var vm, scope, $controller, $rootScope, $injector;
beforeEach(function() {
module('app');
//Inject
inject(function(_$injector_) {
$injector = _$injector_;
$controller = $injector.get('$controller');
$rootScope = $injector.get('$rootScope');
// Create new scope object
scope = $rootScope.$new();
// Bind the controller
vm = $controller('EditorController', {
$scope: scope
});
});
});
describe('#addCustom', function() {
it('test', function(done) {
var aHack = vm.hack(true);
aHack.then(function(bool){
// Resolve
expect(bool).to.be.eq(true);
done();
}, function() {
// Reject
expect(bool).to.be.eq(false);
done();
});
});
});
});