R
R
Roman Ogarkov2016-06-14 18:47:31
Angular
Roman Ogarkov, 2016-06-14 18:47:31

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 = ''
    }
  }]);
});

I create a test
define([
  'angular',
  'app',
  'controllers/rootCtrls/main', 
  'angularMocks'
], 
function (angular, app, mainCtrl) {
  describe('mainCtrl', function () {
    it('should behave...', function() {
      
    });
  });
});

How can I write a test to check the value in a variable$scope.class

Answer the question

In order to leave comments, you need to log in

1 answer(s)
N
Nicholas, 2016-06-14
@ogarich89

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 question

Ask a Question

731 491 924 answers to any question