3

ログイン機能を単体テストしようとしていますが、機能を実行することはできますが、$http 要求を処理しません。これは、コンソールに「関数の実行」を記録しますが、「成功」または「エラー」を記録しないためです。誰でもエラーを知っていますか?ありがとう!

ホームコントローラー

$scope.login = function() {
    console.log('run function')
    $http.post(
        'http://0.0.0.0:8000/api/auth/login/', {
            email: $scope.email,
            password: $scope.password
        }
    )
        .success(function(data) {
            console.log("success");
        })
        .error(function(error) {
            console.log("error");
        });
};

homeControllerTest

describe('homeController', function() {
    beforeEach(module('simulatorApp'));

    var $controller;
    beforeEach(inject(function (_$controller_) {
        $controller = _$controller_;
    }));

    var $scope = {};
    beforeEach(inject(function ($controller, $httpBackend) {
        $httpBackend.whenPOST("http://0.0.0.0:8000/api/auth/login/").respond('response');
        $controller('homeController', {
            $scope: $scope
        });
        $scope.login()
    }));

    describe('Authentication', function () {

        it('Authenticates User', function () {
            $scope.email = 'testuser1@j.com';
            $scope.password = 'password';
            $scope.login();
        })
    })
})
4

0 に答える 0