Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP

Loading…

$history.activeIndex errors in my testing #154

Closed
caseman72 opened this Issue · 12 comments

3 participants

@caseman72

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

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

@tbosch

Hi,
could you provide a jsfiddle / plunk?

Tobias

@caseman72

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

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

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

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

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

@tbosch

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
Do you only have this problem during automatic unit tests,
or also when clicking around in your app?

Only in testing.

@caseman72

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

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
@tbosch

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
Something went wrong with that request. Please try again.