I've encountered an issue while trying to conduct unit testing on my ionic app. Despite checking previous queries, none of the given solutions seem to work for me. Any suggestions on what might be causing this error?
The error message I'm receiving is as follows:
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://errors.angularjs.org/1.4.3/ng/areq?p0=StockCtrl&p1=not%20a%20function%2C%20got%20undefined
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)
Here is a snippet from stockFactory.js file:
app.factory('stockService', function($resource){
return $resource('js/shopStock.json/:items', 'items');
})
And here's code from stockController.js:
app.controller("StockCtrl", function($scope, $rootScope, $stateParams, stockService) {
var items = stockService.get(function(){
$scope.stock = items['items'];
});
});
For Unit Testing, here is 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 attempted using 'module' instead of 'angular.module' as recommended but was met with another 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://errors.angularjs.org/1.4.3/$injector/nomod?p0=ionic
Your guidance and assistance would be highly appreciated.
Furthermore, does anyone have insights on how to test $resource as a next step?