Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

Already on GitHub? Sign in to your account

$history.activeIndex errors in my testing #154

Closed
caseman72 opened this Issue Mar 28, 2013 · 12 comments

Comments

Projects
None yet
3 participants

Line 1560 in restoreOrSaveTransitionForUrlChange:

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

Check activeIndex:

} else if ($history.activeIndex >= 0) {
  $history.urlStack[$history.activeIndex].jqmOptions = navConfig;
}

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

Contributor

tbosch commented Mar 28, 2013

Hi,
could you provide a jsfiddle / plunk?

Tobias

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.

Contributor

tbosch commented Apr 2, 2013

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

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?

Contributor

tbosch commented Apr 3, 2013

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

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

Contributor

tbosch commented Apr 5, 2013

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

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

Only in testing.

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");
Contributor

tbosch commented Apr 15, 2013

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 tbosch closed this in ed6c382 Apr 24, 2013

Contributor

tbosch commented Apr 24, 2013

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

Tobias

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment