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

Testing with Jasmine - Async object not exists #2564

Closed
nischi opened this issue Apr 19, 2017 · 4 comments
Closed

Testing with Jasmine - Async object not exists #2564

nischi opened this issue Apr 19, 2017 · 4 comments

Comments

@nischi
Copy link

nischi commented Apr 19, 2017

RxJS version:
5.3.0

Code to reproduce:
https://github.com/nischi/angular-testing
angular/angular#15889

Expected behavior:
Test should fail because array do not exists

Actual behavior:
Test pass

Additional information:
angular/angular#15889
I have discussed that with the angular team, but they said its a problem with rxjs and jasmine not angular itself, thats the reason why i put the issue here as well.

@kwonoj
Copy link
Member

kwonoj commented Apr 19, 2017

It doesn't seem like Rx issue, jasmine seems try to be smart to catch some of unexpected exceptions thrown, and it's shallowed somehow. So in your test code, it asserts

expect(obj.data.length).toBe(100);

and obj.data is undefined, so evaluating obj.data.length will throws exception - reason there isn't any execution to assertion actually occurred.

instead, if you make data property actually available,

class myObject {
  count = 0;
  data: mySecondObject[] = []; //empty array instance exposes `length`
}

now you can see test fails. If you change your assertion like below,

try {
  const a = obj.data.length;
  expect(a).toBe(100);
} catch (e) {
  console.log(e);
}

you can see exception more clear like

image

It is hard to say what makes this causes exactly though, my current assumption is it's somewhat unrelated to Rx's regression - if you're throwing unhandled exception in observer callbacks, Observable can't do lot of things pretty much.

@nischi
Copy link
Author

nischi commented Apr 19, 2017

Sure i can set the Array to a default value. But if i do a async call to an api it could be taht the "data" is not existing. If that is the case it should be fail. And not pass as it does right now.

Do you think i should open an issue on jasmin project?

@kwonoj
Copy link
Member

kwonoj commented Apr 19, 2017

So it seems like #2565 is exact same symptom. Since it isolates cases more clear without involving ng or jasmine, I'm closing this issue and track this under #2565. I need to dig into history if this is intended changes or not.

@kwonoj kwonoj closed this as completed Apr 19, 2017
@lock
Copy link

lock bot commented Jun 6, 2018

This thread has been automatically locked since there has not been any recent activity after it was closed. Please open a new issue for related bugs.

@lock lock bot locked as resolved and limited conversation to collaborators Jun 6, 2018
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants