vendredi 31 juillet 2015

Karma Unit testing of Ionic App. Error: [ng:areq] Argument 'StockCtrl' is not a function, got undefined

I'm getting an error while trying to unit test my ionic app. I went through previously asked questions and non of the answers worked for me. Any ideas what I'm doing wrong?

Error I'm getting:

PhantomJS 1.9.8 (Mac OS X 0.0.0) StockCtrl should have a scope variable defined FAILED
TypeError: 'undefined' is not a function (evaluating 'queueableFn.fn.call(self.userContext)')
Error: [ng:areq] Argument 'StockCtrl' is not a function, got undefined
http://ift.tt/1JBjDXl
undefined
    at assertArg (/Users/Projects/online-shop/www/lib/angular/angular.js:1770)
    at assertArgFn (/Users/Projects/online-shop/www/lib/angular/angular.js:1781)
    at /Users/Projects/online-shop/www/lib/angular/angular.js:8975
    at /Users/Projects/online-shop/www/lib/angular-mocks/angular-mocks.js:1848
    at /Users/Projects/online-shop/test/stockController.spec.js:9
    at invoke (/Users/Projects/online-shop/www/lib/angular/angular.js:4450)
    at workFn (/Users/Projects/online-shop/www/lib/angular-mocks/angular-mocks.js:2404)
PhantomJS 1.9.8 (Mac OS X 0.0.0): Executed 1 of 1 (1 FAILED) ERROR (0.006 secs / 0.007 secs)

stockFactory.js

app.factory('stockService', function($resource){
 return $resource('js/http://ift.tt/1OTCTiR', 'items');
})

stockController.spec.js

app.controller("StockCtrl", function($scope, $rootScope, $stateParams, stockService) {

var items = stockService.get(function(){
    $scope.stock = items['items'];
  });
});

stockController.spec.js

describe('StockCtrl', function() {
  beforeEach(angular.module('Shop'));

   var scope;


   beforeEach(inject(function($rootScope, $controller){
       scope = $rootScope.$new();
      $controller("StockCtrl", {$scope: scope});
  }));

  it("should have a scope variable defined", function() {
      expect(scope).toBeDefined();
   });
});

I have tried'module' instead of 'angular.module' as suggested in one of the previously posted questions but end up with other error:

Error: [$injector:modulerr] Failed to instantiate module Shop due to:
Error: [$injector:modulerr] Failed to instantiate module ionic due to:
Error: [$injector:nomod] Module 'ionic' is not available! You either misspelled the module name or forgot to load it. If registering a module ensure that you specify the dependencies as the second argument.
http://ift.tt/1JBjEdz

I would be very grateful for a help.

Also, does anyone know how test $resource as a next step?

Aucun commentaire:

Enregistrer un commentaire