Note that there are some explanatory texts on larger screens.

plurals
  1. POangular unit test - controller
    primarykey
    data
    text
    <p>Well want to make some unit tests for my controller. I already prepared some stuff and everything works fine, except that the scope is not loading properly. In my controller i set a value user, but in my tests the value do not get set.</p> <pre><code>merchantCreateController = ($scope, $location, Users, keyboardManager) -&gt; $scope.user= sector: [] </code></pre> <p>Now in my unit test i want to test if the user is initialized with that value.</p> <pre><code>define ["controllers/user", "chai", "angular" ,"angularMocks", "app/services"], (directive, chai, angular, mocks) -&gt; describe "controllers.user.create", -&gt; controller = null scope = null user= null sector = null location = null beforeEach -&gt; mocks.module "app.controllers.user" beforeEach -&gt; mocks.module "app.services" beforeEach -&gt; mocks.inject ['$rootScope', '$controller', '$location', 'app.services.user', 'app.services.sector', ($rootScope, $controller, _location, _user, _sector)-&gt; scope = $rootScope.$new() scope.user= sector: [] user = _user location = _location sector = _sector controller = $controller("app.controllers.merchant.edit", $scope: scope, $location: location "app.services.user": user "app.services.sector": sector keyboardManager: bind: -&gt; ) ] it '$scope.user is initialisized', -&gt; console.log scope.user chai.expect(scope.user).to.deep.equal sector: [] </code></pre> <p>any idea why scope.user is not defined, but everything else is in it like the functions that are in this controller</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload