Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/angularjs/22.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/unit-testing/4.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Angularjs 单元测试控制器-需要第二双眼睛_Angularjs_Unit Testing - Fatal编程技术网

Angularjs 单元测试控制器-需要第二双眼睛

Angularjs 单元测试控制器-需要第二双眼睛,angularjs,unit-testing,Angularjs,Unit Testing,您好,我需要帮助编写此控制器功能的测试。我认为我很接近,但我一直期望未定义的值等于{entityId:2,page:19,length:200}。这似乎很奇怪,因为我还有一个几乎相同的测试。如果有人能发现错误或有任何通用的测试建议,我将非常感激 谢谢 $scope.getAll = function (page, length) { accountService.getAccounts(global.activeOrganizationId, page, length).

您好,我需要帮助编写此控制器功能的测试。我认为我很接近,但我一直期望未定义的值等于{entityId:2,page:19,length:200}。这似乎很奇怪,因为我还有一个几乎相同的测试。如果有人能发现错误或有任何通用的测试建议,我将非常感激

谢谢

   $scope.getAll = function (page, length) {

        accountService.getAccounts(global.activeOrganizationId, page, length).then(function (data) {
            $scope.accounts = data;
        });

    };
这就是我目前所拥有的

describe('AccountsController', function () {
    //make module avalible to tests
    beforeEach(module('pb.accounts.controllers'));
    beforeEach(module('ui.router'));
    beforeEach(module('ui.bootstrap'));

    var $controller;
    var mockGlobal = { activeOrganizationId: 0 };
    var mockStateParams = { orgId: 1, entityId: null };
    var mockForm = {};

    var mockAccountSrv = {
        account: {
            entityId: 2,
            page: 19,
            length: 200
        }
    };

    // instantiating controller
    beforeEach(inject(function (_$controller_) {
        // The injector unwraps the underscores (_) from around the parameter names when matching
        $controller = _$controller_;
    }));

describe("getAll() function", function() {
        var controller, scope;


        beforeEach(inject(function ($q) {
            mockAccountSrv.getAccounts = function (entityId, page, length) {
                var defer = $q.defer();
                defer.resolve(this.account);
                return defer.promise;
            };
        }));

        // sets scope of controller before each test
        beforeEach(inject(function ($rootScope) {
            scope = $rootScope.$new();
            controller = $controller('AccountsController',
                {
                    $scope: scope,
                    $stateParams: mockStateParams,
                    global: mockGlobal,
                    accountService: mockAccountSrv
                });
        }));

        it("make sure service promise resolves", function () {
            scope.getAll(mockAccountSrv.account.page, mockAccountSrv.account.length);
            scope.$digest();

            expect(scope.account).toEqual(mockAccountSrv.account);
        });

    });

如果有人想知道我用mockAccountSrv.account而不是.accounts打了一个愚蠢的错误
谢谢你的关注!感谢Nikos

当数据到达
$scope.accounts(最终“s”)时,您是否正在测试
scope.accounts