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

When(done) not failing on callback error #25

Open
TheLudd opened this issue Feb 21, 2014 · 9 comments · May be fixed by #47
Open

When(done) not failing on callback error #25

TheLudd opened this issue Feb 21, 2014 · 9 comments · May be fixed by #47

Comments

@TheLudd
Copy link

TheLudd commented Feb 21, 2014

I noticed that an error in a callback made in a When statement did not cause the test to fail. In my example below only one test will fail, the first one.

require 'jasmine-given'

describe 'fail in given', ->
    Given (done) -> done new Error 'given error'
    Then -> 1 == 1

describe 'fail in when', ->
    When (done) -> done new Error 'when error'
    Then -> 1 == 1
@searls
Copy link
Owner

searls commented Feb 21, 2014

Whoops!

On Fri, Feb 21, 2014 at 5:04 AM, Ludwig Magnusson
[email protected]:

I noticed that an error in a callback made in a When statement did not
cause the test to fail. In my example below only one test will fail, the
first one.

require 'jasmine-given'

describe 'fail in given', ->
Given (done) -> done new Error 'given error'
Then -> 1 == 1

describe 'fail in when', ->
When (done) -> done new Error 'when error'
Then -> 1 == 1

Reply to this email directly or view it on GitHubhttps://github.com//issues/25
.

@searls
Copy link
Owner

searls commented Feb 21, 2014

Upon reviewing your code, I now understand why this doesn't work.

It's because of an implementation detail in how given's specs map back to Jasmine's. There's an impedance mismatch that given has to deal with because a single Jasmine it() could actually map to numerous When, Then, and And statements. Because the Jasmine runner only gives you one done callback per Jasmine operation (beforeEach, afterEach, it, etc.), we actually had to hack in our own done-callback-gathering system that would dole out callbacks as needed and would make sure they're invoked in a waterfall procedure order.

It might be that we just need to look for errors passed to done. I honestly had never run into this before and didn't realize it was part of the convention. Can you point me to any docs/usage/source describing done & arguments?

@TheLudd
Copy link
Author

TheLudd commented Feb 24, 2014

I forgot to mention that I use jasmine-node. I don't know how that affects things. I noticed that jasmine-node only uses jasmine-1.3.1. It is stated in the documentation the the asynchronous support was changed in 2.0. I haven't checked if this fails in the web runner and supporting both is perhaps asking too much.

@searls
Copy link
Owner

searls commented Feb 24, 2014

Be wary of the it(done) style async, because it's been implemented totally separately by a bunch of test runners prior to its official introduction in jasmine 2.0. jasmine-given should work with any of them, but YMMV

@tandrewnichols
Copy link

As an addendum to this, Then (done) and And (done) also don't fail when done is passed an error, undoubtedly for the same reason.

E.g.

Then (done) -> done(new Error('foo'))
And (done) -> done(new Error('bar'))

will report 2 assertions and 0 failures.

@searls
Copy link
Owner

searls commented Aug 10, 2015

Ugh, this really should get fixed

@neall
Copy link
Collaborator

neall commented Aug 12, 2015

I don't completely understand this code yet, but I think this is a properly failing test on the When (done) -> done(new Error()) version of this problem:

https://github.com/neall/jasmine-given/commit/b9b0f575d27c622e0ee39d429d1469d7894cbab1

@tandrewnichols
Copy link

FWIW, it seems like any non-falsy value should fail a test, not just an error. Like When (done) -> done('Error').

@searls
Copy link
Owner

searls commented Aug 12, 2015

True

On Wed, Aug 12, 2015 at 10:25 AM Andrew Nichols [email protected]
wrote:

FWIW, it seems like any non-falsy value should fail a test, not just an
error. Like When (done) -> done('Error').


Reply to this email directly or view it on GitHub
#25 (comment)
.

@neall neall linked a pull request Aug 13, 2015 that will close this issue
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.

4 participants