Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit 36a547b

Browse files
committed
refactor: remove doReload arg used only for testing
We run unit tests in “strict” mode and thus can’t monkey-patch `window.location` nor `window.location.reload`. In order to avoid full page reload, we could pass location as argument, or another level of indirection, something like this: ```js var ourGlobalFunkyLocation = window.location; function reloadWithDebugInfo() { window.name = 'NG_ENABLE_DEBUG_INFO!' + window.name; ourGlobalFunkyLocation.reload(); } // in the test ourGlobalFunkyLocation = { reload: function() {} }; reloadWithDebugInfo(); ourGlobalFunkyLocation = window.location; ``` I don’t think any of these make sense, just so that we can test setting `window.name`. If the `reloadWithDebugInfo` function was more complicated, I would do it. I don’t think it’s worthy to confuse production code with extra logic which purpose was only to make testing possible.
1 parent b3ec730 commit 36a547b

File tree

2 files changed

+2
-22
lines changed

2 files changed

+2
-22
lines changed

src/Angular.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1465,9 +1465,9 @@ function bootstrap(element, modules, config) {
14651465
* The page should reload and the debug information should now be available.
14661466
*
14671467
*/
1468-
function reloadWithDebugInfo(doReload) {
1468+
function reloadWithDebugInfo() {
14691469
window.name = 'NG_ENABLE_DEBUG_INFO!' + window.name;
1470-
if ( doReload !== false ) window.location.reload();
1470+
window.location.reload();
14711471
}
14721472

14731473
var SNAKE_CASE_REGEXP = /[A-Z]/g;

test/AngularSpec.js

Lines changed: 0 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -1099,26 +1099,6 @@ describe('angular', function() {
10991099
});
11001100

11011101

1102-
describe("reloadWithDebugInfo", function() {
1103-
1104-
it("should reload the current page with debugInfo turned on", function() {
1105-
1106-
element = jqLite('<div>{{1+2}}</div>');
1107-
angular.bootstrap(element);
1108-
expect(element.hasClass('ng-scope')).toBe(false);
1109-
dealoc(element);
1110-
1111-
// We pass the false to prevent the page actually reloading
1112-
angular.reloadWithDebugInfo(false);
1113-
1114-
element = jqLite('<div>{{1+2}}</div>');
1115-
angular.bootstrap(element);
1116-
expect(element.hasClass('ng-scope')).toBe(true);
1117-
dealoc(element);
1118-
});
1119-
});
1120-
1121-
11221102
describe('startingElementHtml', function(){
11231103
it('should show starting element tag only', function(){
11241104
expect(startingTag('<ng-abc x="2A"><div>text</div></ng-abc>')).

0 commit comments

Comments
 (0)