I'm getting " timeout of 2000ms exceeded. Ensure the done() callback is being called in this test." while unit testing a service call that responds back with a promise. I am expecting a rejected promise.
UNIT TEST - Karma-Mocha-Chai running on PhantomJS
describe('teamService', function () {
var teamSrvc, q;
beforeEach(angular.mock.module('scCommon'));
beforeEach(angular.mock.inject(function ($q, teamService) {
teamSrvc = teamService;
q = $q;
}));
describe('getTeamsByNameStartWith', function () {
it('should return reject promise when passing invalid text to search', function () {
var invalidFirstArg = 132;
var validSecondArg = 10;
return teamSrvc.getTeamsByNameStartWith(invalidFirstArg, validSecondArg).then(
function (result) {
},
function (err) {
err.should.equal("Invalid text to search argument passed.");
}
);
});
});
});
Below is the service i am testing. I tested the teamService while running the site and it does successfully return a rejected promise.
(function (ng) {
'use strict';
ng.module('scCommon')
.service('teamService', ['$q', '$http', function ($q, $http) {
var getTeamsByNameStartWith = function (textToSearch, optLimit) {
var defer = $q.defer();
if (typeof textToSearch != "string") {
defer.reject("Invalid text to search argument passed.");
return defer.promise;
} else if (typeof optLimit != "number") {
defer.reject("Invalid limit option argument passed.");
return defer.promise;
}
$http.get('url')
.success(function (data) {
defer.resolve(data);
})
.error(function () {
defer.reject("There was an error retrieving the teams");
});
return defer.promise;
};
return {
getTeamsByNameStartWith: getTeamsByNameStartWith
}
}])
})(angular);
I've read through other stack overflow answers and non was successful.
Any ideas?
I appreciate the help.
Thanks,