nchaulet / httpbackend

Http backend mock module for protractor
MIT License
28 stars 10 forks source link

browser.ignoreSynchronization = true #2

Closed rpavlov closed 8 years ago

rpavlov commented 10 years ago

When I set browser.ignoreSynchronization = true and { autoSync: false} a call to backend.sync() yields a UnknownError: unknown error: Cannot read property 'context' of undefined. It's trigged on this line in httpbackend.js this.browser.driver.executeScript(jsBuilder.toString());

You can reproduce this in the e2e test for manual sync:

    it('Test whenGET without auto sync and manual sync', function() {
        browser.ignoreSynchronization = true;
        backend = new HttpBackend(browser, { autoSync: false});
        backend.whenGET(/result/).respond('result');

        browser.get('/');
        element(by.css('#buttonGET')).click();

        backend.whenGET(/result/).respond('resultAfterInit');
        backend.sync();

        element(by.css('#buttonGET')).click();

        var result = element(by.binding('result'));
        expect(result.getText()).toEqual('resultAfterInit');
    });

Any tips would be welcome :)

nchaulet commented 10 years ago

it seems ignoreSynchronization is incompatible with browser.addMockModule method used by httpbackend. I am going to examine this issue

ryanirilli commented 9 years ago

+1, I am having the same issue. Thanks for your support @nchaulet!

nchaulet commented 9 years ago

ignoreSynchronization method is not compatible with browser.addMockModule used in internal by httpbackend, why do you set ignoreSynchronization to true ?

ryanirilli commented 9 years ago

Well I'm not sure but I know that without it waitForAngular() never resolves. I suspect it's my application code but not sure where. we are not doing any type of browser polling using $timeout and our ng-app attribute is on the body tag. Thanks for your response, I really appreciate it

nchaulet commented 9 years ago

Maybe you have a $timeout in an external dependencies ?

ryanirilli commented 9 years ago

yup, I found one. So for clarity here. should all Angular applications that have e2e testing with Protractor just simply never use $timeout for anything?

nchaulet commented 9 years ago

According to the protractor documentation you should never use $timeout but use $interval

ryanirilli commented 9 years ago

got it. So I should even use that for a single timeout and cancel after the first interval. Thanks again Nicolas, you're legend in my book :)

peterhodges commented 9 years ago

Using $timeout is OK, but your app will only synchronize with protractor once all timeouts have resolved.

If you're using a $timeout with a 0 value to perform something in the next digest cycle, that'll be fine.

If, however, you have a $timeout that logs the user out after 10 minutes, the app will never sync. This will need to be replaced with a $interval that you cancel once it's done its job.