Skip to content
This repository was archived by the owner on Apr 4, 2025. It is now read-only.

Commit 088af12

Browse files
author
Erin Altenhof-Long
committed
fix(): add conditional logic to prevent bootstrapping in protractor tests
Previously, running protractor caused a bootstrapping error because protractor also uses NG_DEFER_BOOTSTRAP. This change monkey patches angular.resumeBootstrap when protractor is deferring the bootstrap so that the angular hint modules can be loaded for testing. This fixes an already bootstrapped error received when testing with protractor. This commit does not cause current protractor tests to pass as the angular hint logging system is a work in progress. The protractor tests will test for that output when the logging is complete. Closes #15
1 parent bd1293d commit 088af12

File tree

2 files changed

+47
-22
lines changed

2 files changed

+47
-22
lines changed

hint.js

Lines changed: 36 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -7,11 +7,31 @@ require('angular-hint-dom');
77
require('angular-hint-directives');
88

99
var allModules = ['ngHintDirectives', 'ngHintDom'];
10+
var isTest = false;
11+
if(window.name === 'NG_DEFER_BOOTSTRAP!') {
12+
isTest = true;
13+
var originalResumeBootstrap;
14+
Object.defineProperty(angular, 'resumeBootstrap', {
15+
get: function() {
16+
return function(modules) {
17+
return(originalResumeBootstrap.call(angular, modules.concat(loadHintModules())))
18+
}
19+
},
20+
set: function(resumeBootstrap) {
21+
originalResumeBootstrap = resumeBootstrap;
1022

11-
window.name = 'NG_DEFER_BOOTSTRAP!';
23+
}
24+
});
25+
console.log = function(message) {
26+
var log = document.getElementById('console');
27+
log.innerHTML = message;
28+
}
29+
}
30+
else {
31+
window.name = 'NG_DEFER_BOOTSTRAP!';
32+
}
1233

13-
// determine which modules to load and resume bootstrap
14-
angular.element(document).ready(function() {
34+
function loadHintModules() {
1535
var selectedModules;
1636
var elts;
1737
var includeModules = function(modulesToInclude) {
@@ -20,7 +40,6 @@ angular.element(document).ready(function() {
2040
});
2141
return selected;
2242
};
23-
2443
var excludeModules = function(modulesToExclude) {
2544
var selected = allModules.filter(function(name) {
2645
var notFound = true;
@@ -35,7 +54,6 @@ angular.element(document).ready(function() {
3554
});
3655
return selected;
3756
};
38-
3957
elts = document.querySelectorAll('[ng-hint-include]');
4058
if(elts.length > 0) {
4159
selectedModules = includeModules(elts[0].attributes['ng-hint-include'].value.split(' '));
@@ -52,10 +70,18 @@ angular.element(document).ready(function() {
5270
}
5371
}
5472
}
55-
if(selectedModules != undefined) {
56-
angular.resumeBootstrap(selectedModules);
57-
}
58-
else {
59-
angular.resumeBootstrap();
73+
return selectedModules;
74+
};
75+
76+
// determine which modules to load and resume bootstrap
77+
angular.element(document).ready(function() {
78+
if(!isTest) {
79+
var modules = loadHintModules();
80+
if(modules != undefined) {
81+
angular.resumeBootstrap(modules);
82+
}
83+
else {
84+
angular.resumeBootstrap();
85+
}
6086
}
6187
});

hint_test.js

Lines changed: 11 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,29 +1,28 @@
11
describe('angularHint', function() {
2-
32
describe('angular hint bootstrapping', function() {
4-
it('should warn if ng-hint is called with unknown options', function() {
3+
// it('should warn if ng-hint is called with unknown options', function() {
54

6-
});
5+
// });
76

87

9-
it('should include all modules by ng-hint default', function() {
8+
// it('should include all modules by ng-hint default', function() {
109

11-
});
10+
// });
1211

1312

1413
it('should have an inclusive mode', function() {
15-
//spyOn(console, 'log');
16-
browser.get('http://localhost:8080/e2e/inclusiveHint/#/inclusiveHint%3C/span%3E');
17-
//expect(console.log).toHaveBeenCalled();
14+
browser.get('http://localhost:8080/e2e/inclusiveHint%3C/span%3E');
15+
expect(element(by.id('title')).getText()).toBe('Inclusive Hint Example');
16+
expect(element(by.id('console')).getText().getText()).toBe('Angular best practices are to manipulate the DOM in the view. See: (https://github.com/angular/angular-hint-dom/blob/master/README.md) Expand to view manipulated properties and line numbers.');
1817
});
1918

2019

21-
it('should have an exclusive mode', function() {
20+
// it('should have an exclusive mode', function() {
2221

23-
});
22+
// });
2423

25-
it('should not bootstrap if ng-hint is not included', function() {
24+
// it('should not bootstrap if ng-hint is not included', function() {
2625

27-
});
26+
// });
2827
});
2928
});

0 commit comments

Comments
 (0)