Main module being injected with everything;
require('./dashboard');
module.exports = angular.module('college', ['college.dashboard'])
.config(function ($stateProvider) {
$stateProvider
.state('college.list', {
url: '/college',
templateUrl: '/dashboard/dashboard.html',
controller: 'DashboardCtrl',
authenticate: true
});
})
.factory('ProjectFactory', require('./services/college.service'));
College Index, which makes the dashboard controller available;
module.exports = angular.module('college.dashboard',
[])
.controller('DashboardCtrl', require('./dashboard.controller.js'));
The college controller exposes the following method;
module.exports = function($scope, $rootScope, $state) {
$scope.openCollege = function(id) {
$rootScope.currentCollege = id;
$state.go('college.main', {currentCollege: id});
};
};
The following error is thrown when the unit test calls
scope.openCollege (2);
Error:
Error: Could not resolve 'college.main' from state ''
Creating state;
beforeEach(inject(function ($rootScope, $state, $location, $controller) {
scope = $rootScope.$new();
location = $location;
rootScope = $rootScope;
$rootScope.currentCollege = {};// Empty by default
state = $state;
$controller('DashboardCtrl', {
$scope: scope,
$state: state,
$location: location
});
}));
Some of the spec test code;
expect(state.current.name).to.equal('');
scope.openCollege(2);
I need to figure out how to handle/mock $state.go during the Karma unit testing so that state knows about college.main.
Any help is appreciated.
J
Here is how I got it working;
I added the following to the spec test;
// Globally defined
var stateSpy;
// within the beforeEach
stateSpy = sinon.stub($state, 'go');
// In the unit test
scope.openCollege (2);
assert(stateSpy.withArgs('college.main', '{currentCollege: 2}').calledOnce);
Note: the $state was not passed to the the controller.
I now have green tests!
Thanks for your help, gave me the idea of how to make this work.
J
I have the same config blocks for all the angular apps on my site, all in different files. app_1.config([ "$httpProvider", function($httpProvider) { $httpProvider.defaults.headers.common['X-...
I have the same config blocks for all the angular apps on my site, all in different files. app_1.config([ "$httpProvider", function($httpProvider) { $httpProvider.defaults.headers.common['X-...
I want to generate a new unique 20 digits string from a string that represent a number For example : var uid = key.pseudoHash("00000000000000000000"), // "45021-78054-45021-16875" uid = key....
I want to generate a new unique 20 digits string from a string that represent a number For example : var uid = key.pseudoHash("00000000000000000000"), // "45021-78054-45021-16875" uid = key....
I'm developing an extension for Google Chrome and the problem I'm having is I need to be able to call a JavaScript function that belongs to the webpage that's opened in the tab. For details, the ...
I'm developing an extension for Google Chrome and the problem I'm having is I need to be able to call a JavaScript function that belongs to the webpage that's opened in the tab. For details, the ...
There was an error in my code and there was also a js file included inside my page which prevented anything from executing inside $(document).ready(function () { ... i'm trying to sumbit this login ...
There was an error in my code and there was also a js file included inside my page which prevented anything from executing inside $(document).ready(function () { ... i'm trying to sumbit this login ...