Skip to content

Commit 5b74b71

Browse files
committed
test(bootstrap): test exception siling during bootstrap
Closes angular#1018
1 parent 4f0be2a commit 5b74b71

File tree

1 file changed

+40
-20
lines changed

1 file changed

+40
-20
lines changed

test/AngularSpec.js

Lines changed: 40 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -322,7 +322,7 @@ describe('angular', function() {
322322

323323

324324
describe('angularInit', function() {
325-
var bootstrap;
325+
var bootstrapSpy;
326326
var element;
327327

328328
beforeEach(function() {
@@ -341,74 +341,83 @@ describe('angular', function() {
341341
return element[name];
342342
}
343343
};
344-
bootstrap = jasmine.createSpy('bootstrap');
344+
bootstrapSpy = jasmine.createSpy('bootstrapSpy');
345345
});
346346

347347

348348
it('should do nothing when not found', function() {
349-
angularInit(element, bootstrap);
350-
expect(bootstrap).not.toHaveBeenCalled();
349+
angularInit(element, bootstrapSpy);
350+
expect(bootstrapSpy).not.toHaveBeenCalled();
351351
});
352352

353353

354354
it('should look for ngApp directive as attr', function() {
355355
var appElement = jqLite('<div ng-app="ABC"></div>')[0];
356356
element.querySelectorAll['[ng-app]'] = [appElement];
357-
angularInit(element, bootstrap);
358-
expect(bootstrap).toHaveBeenCalledOnceWith(appElement, ['ABC']);
357+
angularInit(element, bootstrapSpy);
358+
expect(bootstrapSpy).toHaveBeenCalledOnceWith(appElement, ['ABC']);
359359
});
360360

361361

362362
it('should look for ngApp directive in id', function() {
363363
var appElement = jqLite('<div id="ng-app" data-ng-app="ABC"></div>')[0];
364364
jqLite(document.body).append(appElement);
365-
angularInit(element, bootstrap);
366-
expect(bootstrap).toHaveBeenCalledOnceWith(appElement, ['ABC']);
365+
angularInit(element, bootstrapSpy);
366+
expect(bootstrapSpy).toHaveBeenCalledOnceWith(appElement, ['ABC']);
367367
});
368368

369369

370370
it('should look for ngApp directive in className', function() {
371371
var appElement = jqLite('<div data-ng-app="ABC"></div>')[0];
372372
element.querySelectorAll['.ng\\:app'] = [appElement];
373-
angularInit(element, bootstrap);
374-
expect(bootstrap).toHaveBeenCalledOnceWith(appElement, ['ABC']);
373+
angularInit(element, bootstrapSpy);
374+
expect(bootstrapSpy).toHaveBeenCalledOnceWith(appElement, ['ABC']);
375375
});
376376

377377

378378
it('should look for ngApp directive using querySelectorAll', function() {
379379
var appElement = jqLite('<div x-ng-app="ABC"></div>')[0];
380380
element.querySelectorAll['[ng\\:app]'] = [ appElement ];
381-
angularInit(element, bootstrap);
382-
expect(bootstrap).toHaveBeenCalledOnceWith(appElement, ['ABC']);
381+
angularInit(element, bootstrapSpy);
382+
expect(bootstrapSpy).toHaveBeenCalledOnceWith(appElement, ['ABC']);
383383
});
384384

385385

386386
it('should bootstrap using class name', function() {
387387
var appElement = jqLite('<div class="ng-app: ABC;"></div>')[0];
388-
angularInit(jqLite('<div></div>').append(appElement)[0], bootstrap);
389-
expect(bootstrap).toHaveBeenCalledOnceWith(appElement, ['ABC']);
388+
angularInit(jqLite('<div></div>').append(appElement)[0], bootstrapSpy);
389+
expect(bootstrapSpy).toHaveBeenCalledOnceWith(appElement, ['ABC']);
390390
});
391391

392392

393393
it('should bootstrap anonymously', function() {
394394
var appElement = jqLite('<div x-ng-app></div>')[0];
395395
element.querySelectorAll['[x-ng-app]'] = [ appElement ];
396-
angularInit(element, bootstrap);
397-
expect(bootstrap).toHaveBeenCalledOnceWith(appElement, []);
396+
angularInit(element, bootstrapSpy);
397+
expect(bootstrapSpy).toHaveBeenCalledOnceWith(appElement, []);
398398
});
399399

400400

401401
it('should bootstrap anonymously using class only', function() {
402402
var appElement = jqLite('<div class="ng-app"></div>')[0];
403-
angularInit(jqLite('<div></div>').append(appElement)[0], bootstrap);
404-
expect(bootstrap).toHaveBeenCalledOnceWith(appElement, []);
403+
angularInit(jqLite('<div></div>').append(appElement)[0], bootstrapSpy);
404+
expect(bootstrapSpy).toHaveBeenCalledOnceWith(appElement, []);
405405
});
406406

407407

408408
it('should bootstrap if the annotation is on the root element', function() {
409409
var appElement = jqLite('<div class="ng-app"></div>')[0];
410-
angularInit(appElement, bootstrap);
411-
expect(bootstrap).toHaveBeenCalledOnceWith(appElement, []);
410+
angularInit(appElement, bootstrapSpy);
411+
expect(bootstrapSpy).toHaveBeenCalledOnceWith(appElement, []);
412+
});
413+
414+
415+
it('should complain if app module cannot be found', function() {
416+
var appElement = jqLite('<div ng-app="doesntexist"></div>')[0];
417+
418+
expect(function() {
419+
angularInit(appElement, bootstrap);
420+
}).toThrow('No module: doesntexist');
412421
});
413422
});
414423

@@ -546,6 +555,17 @@ describe('angular', function() {
546555
expect(element.data('$injector')).toBe(injector);
547556
dealoc(element);
548557
});
558+
559+
it("should complain if app module can't be found", function() {
560+
var element = jqLite('<div>{{1+2}}</div>');
561+
562+
expect(function() {
563+
angular.bootstrap(element, ['doesntexist']);
564+
}).toThrow('No module: doesntexist');
565+
566+
expect(element.html()).toBe('{{1+2}}');
567+
dealoc(element);
568+
});
549569
});
550570

551571

0 commit comments

Comments
 (0)