Skip to content
New issue

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

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Promises aren't resolved when testing with angular-mocks #12

Closed
meyertee opened this issue May 6, 2015 · 2 comments · Fixed by #13
Closed

Promises aren't resolved when testing with angular-mocks #12

meyertee opened this issue May 6, 2015 · 2 comments · Fixed by #13

Comments

@meyertee
Copy link
Contributor

meyertee commented May 6, 2015

Hi,

I ran into an issue with how traverson-angular wraps and overwrites the prototype-methods of Traverson's Builder when testing with angular-mocks.

Angular-mocks re-initializes all dependencies for every test, causing the traversonAngular factory-function to execute before every unit test, which in turn wraps the Builder's prototype-methods multiple times. Once they're wrapped multiple times the promises don't properly resolve anymore for the client code.

I fixed it by moving the originalMethods initialisation outside the factory method. I'll send the pull request in a minute.

I've added a dependency to angular-mocks and a spec that executes two tests after each other, hope that's ok for you. Without the change in the code the second test will fail with a time out.

Thank you for creating Traverson!
Thomas.

@basti1302
Copy link
Member

Seems I have broken this again with some refactorings in Traverson.

More specifically, after a relatively big refactoring in in traverson (418abd5365a) these tests stopped working.

I tried to debug it but could not pin it down. The mocked httpBackend still responds but calling deferred.resolve (traverson-angular.js, line 49) does not trigger the then-function in the tests. Tbqh, I have no idea why. The mentioned commit added an additional level of asynchronicity to the call flow in traverson but since we are back in traverson-angular.js and actually calling deferred.resolve(result) I don't believe the problem is in traverson. I'm quite at a loss here.

@meyertee Thomas, I know it's been a while but would it be possible for you to take a look on this? Maybe you see something that I am missing.

Kind regards

Bastian

@basti1302
Copy link
Member

Well, never mind. After writing this, I digged some more. I totally forgot about the silver bullet of JS, just add a little setTimeout in the right spot, all problems go away :-/

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants