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

Failed: Uncaught (in promise): [throw error....] #1335

Closed
yasiryc opened this issue Apr 26, 2017 · 2 comments
Closed

Failed: Uncaught (in promise): [throw error....] #1335

yasiryc opened this issue Apr 26, 2017 · 2 comments

Comments

@yasiryc
Copy link

yasiryc commented Apr 26, 2017

  • What version are you using?
    "jasmine-core": "~2.5.2",
    "jasmine-spec-reporter": "~3.2.0",

  • What environment are you running Jasmine in (node, browser, etc)?
    Angular 4.0.1 via angular cli

  • How are you running Jasmine (standalone, npm, karma, etc)?
    ng test

  • If possible, include an example spec that demonstrates your issue.

I have a login page which call authentication service to authenticate the users. If there user's credentials are invalid then it throws an observable error back to login method (which is of type void).. The unit test is throwing uncaught exception like..

Failed: Uncaught (in promise): The username or password is invalid

I have tried to use following but it didn't help

expect(app.login()).toThrow( new Error("The username or password is invalid"));

@slackersoft
Copy link
Member

Assuming that app.login() is the thing that is throwing the Error, I think you probably want something more like:

expect(function() {
  app.login();
}).toThrowError("The username or password is invalid");

When you use expect(app.login()), the login function is already called and its output is passed to expect.

In the future, you are more likely to get quicker responses from the community for "How to use jasmine?" questions and a history of other solutions on the jasmine-js group. We try to keep jasmine's github issues list focused on bugs and feature requests for jasmine itself.

Hope this helps. Closing this.

@yasiryc
Copy link
Author

yasiryc commented May 3, 2017

Thank you!. I do have followup question but will take it up to right group.

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

2 participants