Sharing Top Content from the Angular-sphere.

Inject Controller and Mock AngularJS Services – Angular.js Recipes – Medium

  • ProblemI’ve finally managed to complete a very simple end to end test, i.e.In scenarios.js:describe(‘My app’, function () { beforeEach(function () { browser().
  • 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 () { Item’); element(‘#add’).
  • toEqual(1); });});But before I run this test I want to Mock the storage service my app is dependant on.Here is my controller [‘$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).
  • Problem courtesy of: GregSolutionTryfunction MyController($scope, $routeParams, $filter, storage) {}MyCtrl1.
  • $inject = [‘$scope’, ‘$routeParams’, ‘$filter’, ‘storage’];Solution courtesy of: daddywoodlandView additional discussion.

“Inject Controller and Mock AngularJS Services” is published by Angular.js Recipes

@_adeeb: Inject Controller and Mock AngularJS Services #javascript #angular #angularjs

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

In scenarios.js:

And my runner.html looks like this:

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:

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

Here is my controller definition:

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

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

Problem courtesy of: Greg

Solution courtesy of: daddywoodland

Inject Controller and Mock AngularJS Services – Angular.js Recipes – Medium

Comments are closed, but trackbacks and pingbacks are open.