opitzconsulting / jquery-mobile-angular-adapter

jquery mobile angular adapter
MIT License
517 stars 114 forks source link

$history.activeIndex errors in my testing #154

Closed caseman72 closed 11 years ago

caseman72 commented 11 years ago

Line 1560 in restoreOrSaveTransitionForUrlChange:

} else {
  $history.urlStack[$history.activeIndex].jqmOptions = navConfig;
}

Check activeIndex:

} else if ($history.activeIndex >= 0) {
  $history.urlStack[$history.activeIndex].jqmOptions = navConfig;
}
caseman72 commented 11 years ago

TypeError: 'undefined' is not an object (evaluating '$history.urlStack[$history.activeIndex].jqmOptions = navConfig')

tbosch commented 11 years ago

Hi, could you provide a jsfiddle / plunk?

Tobias

caseman72 commented 11 years ago

I only see this error in testing but it throws an exception.

I don't think "$history.urlStack[-1]" exists and thus should prevent that from trying to set it - IMHO.

tbosch commented 11 years ago

Yes, think so too. But this should never happen though. I think this is just the result of another problem... So would be really great to have a jsfiddle / plunk to dig a little deeper :-)

Tobias

rodcloutier commented 11 years ago

Hi Tobias,

I have the same issue with my test. Could you give us some pointers on how to set up a jsfiddle/plunk that would replicate a jasmine spec?

tbosch commented 11 years ago

Hi, mmh, for unit tests you actually need some beforeEach and afterEach processing, so things get cleaned up after every tests. However, for a single unit test, this should also work without. Something like this: http://jsfiddle.net/tigbro/Du2DY/298/

So you only have the problem while executing unit tests? Or could you create a jsfiddle with a defined click series that would result into this problem?

Thanks, Tobias

caseman72 commented 11 years ago

And here's the bug in action: http://jsfiddle.net/WQS6u/

tbosch commented 11 years ago

Hi, the problem is that the adapter registers a decorator for the $browser service, but angular-mocks creates a new $browser service. By this, the decorator of the adapter is not applied to the new $browser service. To make this work, you have to add the following to your tests:

beforeEach(function() {
    module("ng", function($provide) {
        var i;
        for (i=0; i<$.mobile._registerBrowserDecorators.length; i++) {
            $.mobile._registerBrowserDecorators[i]($provide);
        }
    });
});

See here: http://jsfiddle.net/tigbro/WQS6u/1/

The unit tests in the adapter already do this, see test/lib/unittestutils.js.

Do you only have this problem during automatic unit tests, or also when clicking around in your app?

Thanks, Tobias

caseman72 commented 11 years ago
Do you only have this problem during automatic unit tests,
or also when clicking around in your app?

Only in testing.

caseman72 commented 11 years ago

Looking in the test/lib/unittestutils.js file - addClass has two params - in jQuery there's only 1 passed param - is there some other addClass that you are calling ?

lib/unittestUtils.js:        page.addClass("temp", "true");
lib/unittestUtils.js:        wrapperElement.children().addClass("result", "true");
lib/unittestUtils.js:        return $(".result").removeClass("result").addClass("temp", "true");
tbosch commented 11 years ago

Hi, what is missing here is a tutorial on how to test directives with the jqm adapter (See issue #171). I.e. all the stuff that is right now inside the unittestutils.js and also the fact that this is only working with angular-mocks v1.0.1 right now. The problems with $activeIndex is only the top of the iceberg if you are not using the unittestutils.js...

Would that solve your problems so I can close this issue?

Thanks for pointing out the error with page.addClass and the two parameters!

Tobias

tbosch commented 11 years ago

Hi, I just added the additional null check...

Tobias