Angularjs 单元测试承诺$q调用

Angularjs 单元测试承诺$q调用,angularjs,jasmine,Angularjs,Jasmine,我对上述功能进行了如下单元测试: $scope.load = function() { deferred = $q.defer(); myService.send('SomeRequestMessage'); deferred.promise.then(function(data) { var modalPopup = loadModal.open('TITLE', data); modalPoupup.result.then(func

我对上述功能进行了如下单元测试:

$scope.load = function() {
    deferred = $q.defer();
    myService.send('SomeRequestMessage');

    deferred.promise.then(function(data) {
        var modalPopup = loadModal.open('TITLE', data);

        modalPoupup.result.then(function(action) {
            if(angular.isDefined(action.dirName)) {
               myService.sendReq(action.dirName);
            }
        });
    });
};
此测试失败,并抛出“预期为true的false。”

可能在代码行下面执行,并且单元测试expect方法立即验证,而不验证承诺(不确定)


请帮助修复此测试。

什么是发送(
myService.send('SomeRequestMessage');
)功能??回调还是承诺?
$scope.load
函数有缺陷。创造的承诺永远无法解决。这就是单元测试失败的原因。@georgeawg我已经编辑了
$scope.load
函数。这就是你的意思吗?
describe('my tests, ', function () {
    var deferred;
    var lRootScope;
    var lmodalInstance;

    beforeEach(inject(function($q, $rootScope) {
        deferred = $q.defer();
        lRootScope = $rootScope;
        lmodalInstance = sinon.stub( { open: function() {}, close: function() {} } );
        lmodalInstance.open.returns({ result: deferred.promise});
    }));

    xit('should call the popup open method once when the open button is pressed.', function () {

        var callBack =sinon.stub();           
        scope.load();           
        expect(lModalInstance.open.calledOnce).toBe(true);
    });
myService.send('SomeRequestMessage');