Testing ngRoute Promise Resolution and Navigation in Angular.js
This test suite evaluates the promise handling capabilities in ngRoute for Angular.js applications. It focuses on testing route resolution timing, timeout behavior, and navigation between routes with pending promises. The suite ensures robust handling of asynchronous operations during routing.
Test Coverage Overview
Implementation Analysis
Technical Details
Best Practices Demonstrated
angular/angularJs
test/e2e/tests/ng-route-promise.spec.js
'use strict';
describe('ngRoute promises', function() {
beforeEach(function() {
loadFixture('ng-route-promise');
});
it('should wait for route promises', function() {
expect(element.all(by.tagName('li')).count()).toBe(5);
});
it('should time out if the promise takes long enough', function(done) {
// Don't try this at home kids, I'm a protractor dev
browser.manage().timeouts().setScriptTimeout(1000);
browser.waitForAngular().then(function() {
fail('waitForAngular() should have timed out, but didn\'t');
}, done);
});
it('should wait for route promises when navigating to another route', function() {
browser.setLocation('/foo2');
expect(element(by.tagName('body')).getText()).toBe('5');
});
afterEach(function(done) {
// Restore old timeout limit
browser.getProcessedConfig().then(function(config) {
return browser.manage().timeouts().setScriptTimeout(config.allScriptsTimeout);
}).then(done);
});
});