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?!
Try
function MyController($scope, $routeParams, $filter, storage) {}
MyCtrl1.$inject = ['$scope', '$routeParams', '$filter', 'storage'];