question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Protractor does not wait to resolve promises on routes

See original GitHub issue

Hey,

I’m having a few issues getting protractor to wait for my dependencies to load in the route.

The basic code I have is this (which works fine in Angular itself)

$routeProvider.when('/login, {
    templateUrl: 'template.html',
    controller: 'LoginCtrl',
    resolve: {
         dependencies: function($q, $rootScope) {
          var def = $q.defer();
          yepnope([
            {
                load: [
                    'dependencies.js',
                ],
                complete: function () {
                    $rootScope.$apply(function () {
                        def.resolve();
                    });
                }
            }
        ]);
        return def.promise;
        }
     }
 });

Protractor doesn’t wait for the route to resolve and doesn’t even display any content from the route. If the resolve dependency is removed the route successfully loads (but the test fails as the dependency isn’t loaded).

I’ve tried it with $timeout testing and that works fine, and as this isn’t a $http request, is there something I’m missing, or is this just not supported?

Thanks

Issue Analytics

  • State:closed
  • Created 9 years ago
  • Comments:30 (6 by maintainers)

github_iconTop GitHub Comments

1reaction
gkalpakcommented, Jul 15, 2016

@juliemr , I think @sjelin meant angular/angular.js#14159.

1reaction
Smolationscommented, Feb 18, 2015

@yxh10 That is not a long-term solution. Protractor should be aware of the views it’s rendering, as well as when the DOM is ready. Using browser.wait in that fashion may solve the immediate problem, but if it happens across many tests, the spec files would be littered with all of those statements. Not only that, but how would one choose an appropriate timeToWaitInMilliseconds? Having multiple blocks such as the one you have above would significantly slow down testing for larger applications.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Protractor does not wait for Angular to resolve - Stack Overflow
Since it's a timing issue, a workaround can be to wait for the element to be present before you assert that it's present:...
Read more >
protractor-timeline-plugin - npm
* You can use waitForPromise() to have Protractor additionally wait for your * custom promise to be resolved inside of browser.waitForAngular().
Read more >
CHANGELOG.md
It will affect TypeScript tests that are using async/await and a. miss some ... to install and fix reference to protractor - changed...
Read more >
Top 18 Most Common AngularJS Developer Mistakes - Toptal
Common Mistake #5: Not Using Named Views With UI-ROUTER For Power”. The de facto routing solution for AngularJS has been, until now, the...
Read more >
Using async/await - Protractor - end-to-end testing for AngularJS
Note: Never forget to add “await” keyword in an async function, it may bring some unexpected problem (e.g. your test might fail silently...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found