@@ -5,36 +5,49 @@ describe('rootScope', function () {
5
5
// load the controller's module
6
6
beforeEach ( module ( 'yoAngularCordovaApp' ) ) ;
7
7
8
- var scope , rootscope ;
9
-
10
8
// Initialize the controller and a mock scope
11
- beforeEach ( inject ( function ( $controller , $rootScope ) {
12
- scope = $rootScope . $new ( ) ;
13
- rootscope = $rootScope ;
9
+ beforeEach ( inject ( function ( $httpBackend ) {
10
+ $httpBackend . when ( 'GET' , 'views/about.html' ) . respond ( 'about' ) ;
11
+ $httpBackend . when ( 'GET' , 'views/list.html' ) . respond ( 'list' ) ;
12
+ $httpBackend . when ( 'GET' , 'views/main.html' ) . respond ( 'main' ) ;
14
13
} ) ) ;
15
14
16
15
17
16
it ( 'should obey history logic' , function ( ) {
18
- expect ( scope . isHistoryEmpty ( ) ) . toBe ( true ) ;
19
- expect ( scope . isHistory ( ) ) . toBe ( false ) ;
20
-
21
- scope . go ( '/about' ) ;
22
- rootscope . $broadcast ( '$routeChangeSuccess' , { } ) ;
23
- //expect(scope.isHistory()).toBe(true);
24
- //expect(scope.isHistoryEmpty()).toBe(false);
25
-
26
- scope . backFunction ( ) ;
27
- expect ( scope . isHistoryEmpty ( ) ) . toBe ( true ) ;
28
- expect ( scope . isHistory ( ) ) . toBe ( false ) ;
29
-
30
- scope . go ( '/about' ) ;
31
- rootscope . $broadcast ( '$routeChangeSuccess' , { } ) ;
32
- //expect(scope.isHistory()).toBe(true);
33
- //expect(scope.isHistoryEmpty()).toBe(false);
34
-
35
- scope . clearHistory ( ) ;
36
- expect ( scope . isHistoryEmpty ( ) ) . toBe ( true ) ;
37
- expect ( scope . isHistory ( ) ) . toBe ( false ) ;
17
+
18
+ inject ( function ( $route , $location , $rootScope ) {
19
+ expect ( $rootScope . isHistoryEmpty ( ) ) . toBe ( true ) ;
20
+ expect ( $rootScope . isHistory ( ) ) . toBe ( false ) ;
21
+ $rootScope . go ( '/about' ) ;
22
+ $rootScope . $digest ( ) ;
23
+ expect ( $route . current . controller ) . toBe ( 'AboutCtrl' ) ;
24
+ expect ( $route . current . templateUrl ) . toBe ( 'views/about.html' ) ;
25
+ expect ( $route . current . originalPath ) . toBe ( '/about' ) ;
26
+ expect ( $rootScope . isHistoryEmpty ( ) ) . toBe ( true ) ;
27
+ expect ( $rootScope . isHistory ( ) ) . toBe ( false ) ;
28
+
29
+ $rootScope . go ( '/list' ) ;
30
+ $rootScope . $digest ( ) ;
31
+ expect ( $route . current . templateUrl ) . toBe ( 'views/list.html' ) ;
32
+ expect ( $route . current . originalPath ) . toBe ( '/list' ) ;
33
+
34
+ $rootScope . backFunction ( ) ;
35
+ $rootScope . $digest ( ) ;
36
+ expect ( $route . current . controller ) . toBe ( 'MainCtrl' ) ;
37
+ expect ( $route . current . templateUrl ) . toBe ( 'views/main.html' ) ;
38
+ expect ( $route . current . originalPath ) . toBe ( '/' ) ;
39
+ expect ( $rootScope . isHistoryEmpty ( ) ) . toBe ( true ) ;
40
+ expect ( $rootScope . isHistory ( ) ) . toBe ( false ) ;
41
+
42
+ $rootScope . go ( '/list' ) ;
43
+ $rootScope . $digest ( ) ;
44
+ expect ( $route . current . templateUrl ) . toBe ( 'views/list.html' ) ;
45
+ expect ( $route . current . originalPath ) . toBe ( '/list' ) ;
46
+
47
+ $rootScope . clearHistory ( ) ;
48
+ $rootScope . $digest ( ) ;
49
+ } ) ;
50
+
38
51
} ) ;
39
52
40
53
} ) ;
0 commit comments