Answer the question
In order to leave comments, you need to log in
How to set up Angular + RequireJS + jasmineJS?
Help me figure out jasmineJS in conjunction with requireJS and angularJS
I want to test the view controller as an example
define(['../module'], function (controllers) {
'use strict';
controllers.controller('mainCtrl', ['$scope', '$rootScope', '$interval', function ($scope, $rootScope) {
$rootScope.count = 0;
$scope.leftToolbar = true;
$scope.rightToolbar = true;
$scope.class = 'all';
$scope.toolbar = function () {
if ($scope.leftToolbar && $scope.rightToolbar)
$scope.class = 'all'
else if ($scope.leftToolbar)
$scope.class = 'left'
else if ($scope.rightToolbar)
$scope.class = 'right'
else
$scope.class = ''
}
}]);
});
define([
'angular',
'app',
'controllers/rootCtrls/main',
'angularMocks'
],
function (angular, app, mainCtrl) {
describe('mainCtrl', function () {
it('should behave...', function() {
});
});
});
$scope.class
Answer the question
In order to leave comments, you need to log in
See the Angular doc for this. It's all pretty well laid out.
https://docs.angularjs.org/guide/unit-testing
In general, the process is simple:
1. connect the desired module using the module(%module_name%);
2. mock all the necessary dependencies in parallel
3. inject the object under test / well, or in the case of a controller, inject $controller.
4. actually write tests,
inject the necessary service, mock all dependencies -
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question