Selaa lähdekoodia

Add an actual spec, fix notes service name

Lily Carpenter 10 vuotta sitten
vanhempi
commit
b0e53f8f2d
3 muutettua tiedostoa jossa 16 lisäystä ja 5 poistoa
  1. 11 0
      tests/controllerSpec.js
  2. 4 4
      www/js/controllers/noteCtrl.js
  3. 1 1
      www/js/services/notes.js

+ 11 - 0
tests/controllerSpec.js

@@ -1,2 +1,13 @@
1 1
 describe('My notes controller', function(){
2
+  var scope;
3
+  beforeEach(module('bootcampApp'));
4
+  beforeEach(inject(function($rootScope, $controller, _Notes_){
5
+    scope = $rootScope.$new();
6
+    Notes = _Notes_;
7
+    $controller('NoteCtrl', {Notes:Notes,$scope:scope});
8
+  }));
9
+
10
+  it('has a default new note', function(){
11
+    expect(scope.newNote).not.toBeUndefined();
12
+  });
2 13
 });

+ 4 - 4
www/js/controllers/noteCtrl.js

@@ -1,5 +1,5 @@
1 1
 angular.module('bootcampApp')
2
-  .controller('NoteCtrl', function($Notes, $scope){
2
+  .controller('NoteCtrl', function(Notes, $scope){
3 3
     var defaultNote = {
4 4
       "title": "I am a title",
5 5
       "body": "I am a body"
@@ -7,10 +7,10 @@ angular.module('bootcampApp')
7 7
 
8 8
     $scope.notes = [];
9 9
 
10
-    $scope.newNote = $Notes.cloneNote(defaultNote);
10
+    $scope.newNote = Notes.cloneNote(defaultNote);
11 11
 
12 12
     $scope.createNote = function(newNote){
13
-      $scope.notes.push($Notes.cloneNote(newNote));
14
-      $scope.newNote = $Notes.cloneNote(defaultNote);
13
+      $scope.notes.push(Notes.cloneNote(newNote));
14
+      $scope.newNote = Notes.cloneNote(defaultNote);
15 15
     };
16 16
   });

+ 1 - 1
www/js/services/notes.js

@@ -1,5 +1,5 @@
1 1
 angular.module('bootcampApp')
2
-  .factory('$Notes', function(){
2
+  .factory('Notes', function(){
3 3
     function cloneNote(note){
4 4
       var my_note = {};
5 5
       my_note.body = note.body;