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

Presence of ng-token-auth causes problems in controller test #45

Closed
jasonswett opened this issue Oct 7, 2014 · 22 comments
Closed

Presence of ng-token-auth causes problems in controller test #45

jasonswett opened this issue Oct 7, 2014 · 22 comments

Comments

@jasonswett
Copy link
Contributor

I assume I'm just doing something wrong here.

When I try to write an Angular controller test, I get the following error:

TypeError: 'undefined' is not a function (evaluating 'this.handlePostMessage.bind(this)') at /Users/jasonswett/projects/ben_franklin_labs/lunch_hub/client/bower_components/ng-token-auth/dist/ng-token-auth.js:97

Is there some specific extra step I have to take to get ng-token-auth not to cause this error? I'm including other custom modules and those seem to work fine, so I'm kind of at a loss.

I'm submitting this as an issue rather than just a StackOverflow question or something in case it is actually a legitimate issue that needs to be addressed.

@jasonswett
Copy link
Contributor Author

I got my test to run in the following way: http://stackoverflow.com/a/26244247/199712

But it does feel kind of wrong to just entirely mock the module away when I don't have to do that with any other modules I'm including. Again, I don't know if this is something specific to ng-token-auth that needs to be fixed with ng-token-auth or if it's not. Sorry for the distraction if it's not. Any insights appreciated.

@lynndylanhurley
Copy link
Owner

@jasonswett - I'll look into this. I haven't run into this issue in my test suite, but I'll add a similar test and see if I can reproduce the issue.

@jasonswett
Copy link
Contributor Author

@lynndylanhurley Okay, thanks. Do you have any publicly available code from an app that uses ng-token-auth and has Angular controller tests? I could only find the Rails portion of your ng-token-auth demo, which didn't seem to have the client-side code in it.

@lynndylanhurley
Copy link
Owner

I've only been using functional unit tests up to this point. They can all be found here. Note how the test-helper file is required and run by each test, so that the services ($http, $auth, etc.) are all defined as global variables.

I'm also working on setting up an E2E suite using Protractor, but it's been a challenge to get working with Travis CI / Sauce Labs, and I haven't gotten very far.

But I don't have any controller tests that look like yours. I'll create one ASAP, and I'll let you know what I find.

@lynndylanhurley
Copy link
Owner

Oh, and the client code from the demo is actually included in this repo.

Follow these instructions (under the Development section) to run the client demo.

I eventually want to build an E2E test suite against the demo. That is why the code is bundled here rather than in a separate repo.

@jasonswett
Copy link
Contributor Author

Okay, thanks. I think we might actually be talking about two different things. It looks like you're talking about tests that test the ng-token-auth module itself, but I'm talking about tests that test an Angular controller within an application that uses ng-token-auth. Hopefully that makes sense.

@lynndylanhurley
Copy link
Owner

No I totally get it - I don't have any tests like that yet. I'll create one, and I'll let you know what I find.

@jasonswett
Copy link
Contributor Author

My bad - I see now that I was the one who was misunderstanding. Sounds good. Curious to hear what you find.

lynndylanhurley added a commit that referenced this issue Oct 9, 2014
@lynndylanhurley
Copy link
Owner

@jasonswett - I was able to add a controller test without any issues.

There must be some component to this issue that we're not seeing. The error suggests that this does not refer to the module itself, which means that the initialization methods may have been called from outside of the module. Does your code initialize the $auth module in a non-standard way?

@jasonswett
Copy link
Contributor Author

Knowing it's possible to have a problem-free controller test helps a lot. Now I know the problem is something within my project as opposed to something inside of ng-token-auth.

Let me spin up a clean new project and only put ng-token-auth on it. A controller test should work there. Then I'll gradually add my other stuff at see at what point it stops working.

So I think this issue is a non-issue as it pertains to ng-token-auth. If I find something else that does seem like a legitimate issue, I'll open a new, more specific issue for it.

@jasonswett
Copy link
Contributor Author

And thanks again for the help

@lynndylanhurley
Copy link
Owner

No problem @jasonswett! Is your project up on github? Maybe I can help debug.

@jasonswett
Copy link
Contributor Author

Didn't see your comment until just now. Here's the project: https://github.com/jasonswett/lunch_hub/tree/development

@jasonswett
Copy link
Contributor Author

Hmm, I'm still having the problem even with a totally blank Angular project. Maybe I just don't know how to properly initialize the $auth module.

@jasonswett
Copy link
Contributor Author

Woops, meant to link: https://github.com/jasonswett/ng-test

@lynndylanhurley
Copy link
Owner

I'll pull down your project and see if I can diagnose this.

@jasonswett
Copy link
Contributor Author

Thanks.

Jason Swett
Principal, Ben Franklin Labs
Cell: (616) 856-8075

On Oct 21, 2014, at 7:52 PM, Lynn Dylan Hurley [email protected] wrote:

I'll pull down your project and see if I can diagnose this.


Reply to this email directly or view it on GitHub.

lynndylanhurley added a commit that referenced this issue Oct 24, 2014
@lynndylanhurley
Copy link
Owner

@jasonswett - looks like there was something going on with the bind method, but only in testing. I updated this module to use angular.bind instead, and it seems to have fixed the issue.

After upgrading to ng-token-auth v0.0.24-beta1, the test still fails, but it's no longer ng-token-auth that causes the failure. Please test to confirm.

@jasonswett
Copy link
Contributor Author

Awesome!!! Thank you so much. My test is actually passing on my end, so I'm all set.

@EnterpriseWide
Copy link

I was using v0.0.23 and got the error.
I upgraded to v0.0.24-beta1 and got the error.
I looked for bind on line 97 and but still saw "this.listener = this.handlePostMessage.bind(this);". Is there a change to the source that I can make that will stop the error from happening?

@jasonswett
Copy link
Contributor Author

I had the same issue but I don't think it's an ng-token-auth issue. If you look at https://github.com/lynndylanhurley/ng-token-auth/blob/master/src/ng-token-auth.coffee you can see that all the bind() calls have been fixed. I think you have to somehow get Bower to re-download the compiled source.

@EnterpriseWide
Copy link

Yeah gotcha, I copied the dist Ng-token-auth.js file from a new got clone over the top of the bower installed version and it works. Thanks

Sent from my iPhone

On 27 Oct 2014, at 11:16 pm, Jason Swett [email protected] wrote:

I had the same issue but I don't think it's an ng-token-auth issue. If you look at https://github.com/lynndylanhurley/ng-token-auth/blob/master/src/ng-token-auth.coffee you can see that all the bind() calls have been fixed. I think you have to somehow get Bower to re-download the compiled source.


Reply to this email directly or view it on GitHub.

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

No branches or pull requests

3 participants