Skip to content

Commit dbfd9ab

Browse files
committed
clean up rootScope tests
1 parent a0e3b63 commit dbfd9ab

File tree

1 file changed

+38
-25
lines changed

1 file changed

+38
-25
lines changed

test/spec/rootScope.js

Lines changed: 38 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -5,36 +5,49 @@ describe('rootScope', function () {
55
// load the controller's module
66
beforeEach(module('yoAngularCordovaApp'));
77

8-
var scope, rootscope;
9-
108
// 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');
1413
}));
1514

1615

1716
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+
3851
});
3952

4053
});

0 commit comments

Comments
 (0)