1

I've finally managed to complete a very simple end to end test, i.e.

In scenarios.js:

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

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

And my runner.html looks like this:

<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>

This boots up my site, navigates, and checks an input is blank. Ace.

However I would like to now add this test which expands on what I have so far:

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);
    });
});

But before I run this test I want to Mock the storage service my app is dependant on.

Here is my controller definition:

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

And this is causing me problems (I think), because I want to do something like this:

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

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

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

But can't because of the way I am declaring my Controller. And the reason I am declaring my controller that way is for minification purposes...

Does anyone have an advice on how this problem could be solved?!

1
  • Would be great to add your testatcular config file, in particular you probably have specified a urlRoot other than '/', in order to support your browser().navigateTo('/') Commented Nov 30, 2012 at 21:55

1 Answer 1

3

Try

function MyController($scope, $routeParams, $filter, storage) {}
MyCtrl1.$inject = ['$scope', '$routeParams', '$filter', 'storage'];
Sign up to request clarification or add additional context in comments.

1 Comment

I found this - docs.angularjs.org/tutorial/step_05 - on the Angular Tutorial (which I never read!) which has the answer and reason why this is correct. "A note on minification"...

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.