1

我终于设法完成了一个非常简单的端到端测试,即

场景.js 中:

describe('My app', function () {
    beforeEach(function () {
        browser().navigateTo('/');
    });

    describe('On Load', function () {
        it('Textbox should be blank', function () {
            expect(input('textbox').val()).toBe('');
        });
    });
});

我的runner.html看起来像这样:

<head>
    <title>End2end Test Runner</title>
    <script src="/js/libs/angular-scenario.js" ng-autotest></script>
    <script src="/js/libs/angular-mocks.js"></script>
    <script src="/js/test/e2e/scenarios.js"></script>
</head>

这会启动我的网站、导航并检查输入是否为空白。高手。

但是我现在想添加这个测试,它扩展了我到目前为止的内容:

describe('Click on Add', function () {
    it('will add new item if valid', function () {
        input('newItemName').enter('Test Item');
        element('#add').click();
        expect(input('newItemName').val()).toBe('');
        expect(repeater('#items li').count()).toEqual(1);
    });
});

但在我运行这个测试之前,我想模拟我的应用程序所依赖的存储服务。

这是我的控制器定义

myapp.controller('MyController', ['$scope', '$routeParams', '$filter', 'storage',
    function ($scope, $routeParams, $filter, storage) { 
        . . . . 
    }
]);

这给我带来了问题(我认为),因为我想做这样的事情:

describe('Controller Unit Tests', function(){
    var ctrl;

    beforeEach(function(){
        ctrl = new MyController();
    });

    it('should ....', function() {
        expect(true).toBe(true);
    });
});

但不能因为我声明我的控制器的方式。我以这种方式声明我的控制器的原因是为了缩小目的......

有没有人对如何解决这个问题有建议?!

4

1 回答 1

3

尝试

function MyController($scope, $routeParams, $filter, storage) {}
MyCtrl1.$inject = ['$scope', '$routeParams', '$filter', 'storage'];
于 2012-09-20T15:45:55.887 回答