Note that there are some explanatory texts on larger screens.

plurals
  1. POAngularjs: angular-phonecat tutorial app fails first unit test
    text
    copied!<p>Just starting to learn Angularjs &amp; unit-testing with jasmine...</p> <p>Following tutorial on <a href="http://docs.angularjs.org/tutorial/step_02" rel="noreferrer">http://docs.angularjs.org/tutorial/step_02</a> to find that the very first unit test (which should pass because <code>scope.phones.length</code> is 3) fails.</p> <pre><code>INFO [karma]: Karma v0.10.2 server started at http://localhost:9876/ INFO [launcher]: Starting browser Chrome INFO [Chrome 30.0.1599 (Mac OS X 10.8.5)]: Connected on socket BdjA1lVT9OOo8kgQKLYs Chrome 30.0.1599 (Mac OS X 10.8.5) PhoneCat controllers PhoneListCtrl should create "phones" model with 3 phones FAILED ReferenceError: PhoneListCtrl is not defined at null.&lt;anonymous&gt; (/Applications/MAMP/htdocs/angular-phonecat/test/unit/controllersSpec.js:12:22) Chrome 30.0.1599 (Mac OS X 10.8.5): Executed 2 of 2 (1 FAILED) (0.37 secs / 0.033 secs) </code></pre> <p>So basically, it is stating that PhoneListCtrl is not defined. However the app is working perfectly, and I don't really know where to start considering I am at the beginning of the tutorial!</p> <p>Here is my unit test which is the default from the tutorial.</p> <p><strong>test/unit/controllerSpec.js</strong></p> <pre><code>'use strict'; /* jasmine specs for controllers go here */ describe('PhoneCat controllers', function() { describe('PhoneListCtrl', function(){ beforeEach(module('phonecatApp')); it('should create "phones" model with 3 phones', function() { var scope = {}, ctrl = new PhoneListCtrl(scope); expect(scope.phones.length).toBe(3); }); it('should create "phones" model with 3 phones', inject(function($controller) { var scope = {}, ctrl = $controller('PhoneListCtrl', {$scope:scope}); expect(scope.phones.length).toBe(3); })); }); }); </code></pre> <p><strong>app/js/controller.js</strong></p> <pre><code>'use strict'; /* Controllers */ var phonecatApp = angular.module('phonecatApp', []); phonecatApp.controller('PhoneListCtrl', function PhoneListCtrl($scope) { $scope.phones = [ {'name': 'Nexus S', 'snippet': 'Fast just got faster with Nexus S.'}, {'name': 'Motorola XOOM™ with Wi-Fi', 'snippet': 'The Next, Next Generation tablet.'}, {'name': 'MOTOROLA XOOM™', 'snippet': 'The Next, Next Generation tablet.'} ]; $scope.hello = "Hello World"; }); </code></pre> <p>config/karma.conf.js <a href="http://pastebin.com/PPWjSmyJ" rel="noreferrer">http://pastebin.com/PPWjSmyJ</a></p>
 

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