Note that there are some explanatory texts on larger screens.

plurals
  1. POHow to inject dependencies in jasmine test for an angular item
    primarykey
    data
    text
    <p>Here is the test spec file:</p> <pre><code>describe('Test main controller', function(){ it('Should initialize value to Loading', function(){ $scope = {} ctrl = new mainNavController($scope) expect($scope.wksp_name).toBe('Loading') }) }) </code></pre> <p>Here is the controller file</p> <pre><code>function mainNavController($scope) { $scope.wksp_name = 'Loading...' $scope.$on('broadCastWkspNameEvent', function (e, args) { $scope.wksp_name = args }) } mainNavController.$inject=['$scope'] </code></pre> <p>But my test fails saying <code>Object #&lt;Object&gt; has no method '$on'</code></p> <p>I am using the basic setup of jasmine. </p> <pre><code>&lt;!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd"&gt; &lt;html&gt; &lt;head&gt; &lt;title&gt;Jasmine Spec Runner&lt;/title&gt; &lt;link rel="shortcut icon" type="image/png" href="testlib/jasmine-1.2.0/jasmine_favicon.png"&gt; &lt;link rel="stylesheet" type="text/css" href="testlib/jasmine-1.2.0/jasmine.css"&gt; &lt;script type="text/javascript" src="testlib/jasmine-1.2.0/jasmine.js"&gt;&lt;/script&gt; &lt;script type="text/javascript" src="testlib/jasmine-1.2.0/jasmine-html.js"&gt;&lt;/script&gt; &lt;!-- include source files here... --&gt; &lt;script type="text/javascript" src="/static_files/js/test-specs/main-nav-spec.js"&gt;&lt;/script&gt; &lt;!-- include spec files here... --&gt; &lt;script type="text/javascript" src="/static_files/js/common/jquery/latest.js"&gt;&lt;/script&gt; &lt;script type="text/javascript" src="/static_files/js/common/angular/angular-1.0.1.min.js"&gt;&lt;/script&gt; &lt;script type="text/javascript" src="/static_files/js/common/angular/angular-resource-1.0.1.min.js"&gt;&lt;/script&gt; &lt;script type="text/javascript" src="/static_files/js/section/main-nav-controller.js"&gt;&lt;/script&gt; &lt;script type="text/javascript"&gt; (function() { var jasmineEnv = jasmine.getEnv(); jasmineEnv.updateInterval = 1000; var htmlReporter = new jasmine.HtmlReporter(); jasmineEnv.addReporter(htmlReporter); jasmineEnv.specFilter = function(spec) { return htmlReporter.specFilter(spec); }; var currentWindowOnload = window.onload; window.onload = function() { if (currentWindowOnload) { currentWindowOnload(); } execJasmine(); }; function execJasmine() { jasmineEnv.execute(); } })(); &lt;/script&gt; &lt;/head&gt; &lt;body&gt; &lt;/body&gt; &lt;/html&gt; </code></pre> <p>What is it that I am doing wrong? I am not able to understand how this thing is supposed to work :)</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