1
1
describe ( 'example.personalLog.LogCtrl' , function ( ) {
2
2
var logScope ;
3
3
4
- beforeEach ( function ( ) {
5
- var injector = angular . injector ( [ 'ng' , 'ngMock' , 'ngCookies' ] ) ;
6
- logScope = injector . get ( '$rootScope' ) ;
7
- logScope . $cookies = injector . get ( '$cookies' ) ;
8
- injector . instantiate ( example . personalLog . LogCtrl , { $scope : logScope } ) ;
9
- } ) ;
4
+
5
+ beforeEach ( module ( 'personalLog' ) ) ;
6
+
7
+ beforeEach ( inject ( function ( $rootScope , $controller ) {
8
+ logScope = $rootScope . $new ( ) ;
9
+ $controller ( 'LogCtrl' , { $scope : logScope } ) ;
10
+ } ) ) ;
10
11
11
12
12
13
it ( 'should initialize notes with an empty array' , function ( ) {
@@ -43,11 +44,11 @@ describe('example.personalLog.LogCtrl', function() {
43
44
} ) ;
44
45
45
46
46
- it ( 'should store logs in the logs cookie' , function ( ) {
47
- expect ( logScope . $cookies . logs ) . not . toBeDefined ( ) ;
47
+ it ( 'should store logs in the logs cookie' , inject ( function ( $cookies ) {
48
+ expect ( $cookies . logs ) . not . toBeDefined ( ) ;
48
49
logScope . addLog ( 'first log message' ) ;
49
- expect ( logScope . $cookies . logs ) . toBeTruthy ( ) ;
50
- } ) ;
50
+ expect ( $cookies . logs ) . toBeTruthy ( ) ;
51
+ } ) ) ;
51
52
52
53
53
54
it ( 'should do nothing if newMsg is empty' , function ( ) {
@@ -79,17 +80,17 @@ describe('example.personalLog.LogCtrl', function() {
79
80
} ) ;
80
81
81
82
82
- it ( 'should update cookies when a log is deleted' , function ( ) {
83
- expect ( logScope . $cookies . logs ) . toMatch ( / \[ \{ .* ?\} ( , \{ .* ?\} ) { 3 } \] / ) ;
83
+ it ( 'should update cookies when a log is deleted' , inject ( function ( $cookies ) {
84
+ expect ( $cookies . logs ) . toMatch ( / \[ \{ .* ?\} ( , \{ .* ?\} ) { 3 } \] / ) ;
84
85
85
86
logScope . rmLog ( logScope . logs [ 1 ] ) ;
86
- expect ( logScope . $cookies . logs ) . toMatch ( / \[ \{ .* ?\} ( , \{ .* ?\} ) { 2 } \] / ) ;
87
+ expect ( $cookies . logs ) . toMatch ( / \[ \{ .* ?\} ( , \{ .* ?\} ) { 2 } \] / ) ;
87
88
88
89
logScope . rmLog ( logScope . logs [ 0 ] ) ;
89
90
logScope . rmLog ( logScope . logs [ 0 ] ) ;
90
91
logScope . rmLog ( logScope . logs [ 0 ] ) ;
91
- expect ( logScope . $cookies . logs ) . toMatch ( / \[ \] / ) ;
92
- } ) ;
92
+ expect ( $cookies . logs ) . toMatch ( / \[ \] / ) ;
93
+ } ) ) ;
93
94
} ) ;
94
95
95
96
@@ -110,10 +111,10 @@ describe('example.personalLog.LogCtrl', function() {
110
111
} ) ;
111
112
112
113
113
- it ( 'should remove logs cookie' , function ( ) {
114
- expect ( logScope . $cookies . logs ) . toBeTruthy ( ) ;
114
+ it ( 'should remove logs cookie' , inject ( function ( $cookies ) {
115
+ expect ( $cookies . logs ) . toBeTruthy ( ) ;
115
116
logScope . rmLogs ( ) ;
116
- expect ( logScope . $cookies . logs ) . not . toBeDefined ( ) ;
117
- } ) ;
117
+ expect ( $cookies . logs ) . not . toBeDefined ( ) ;
118
+ } ) ) ;
118
119
} ) ;
119
120
} ) ;
0 commit comments