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

verifiable thenThrow #288

Closed
andreventuravale opened this issue Sep 19, 2017 · 2 comments
Closed

verifiable thenThrow #288

andreventuravale opened this issue Sep 19, 2017 · 2 comments

Comments

@andreventuravale
Copy link

Hi,

I would like to have a way to accomplish a verifiable thenThrow.

Ex:

    describe('Question 1', function () {

        describe('Given a closure as argument that causes an error when executed', function () {

            beforeEach(function () {

                this.closure = td.function();

                td.when(this.closure()).thenThrow('foo');
            });

            it('Find a way to handle this error', function () {

                expect(function () {

                    answers.question1(this.closure);

                }.bind(this)).not.throws();

                td.verify(this.closure());
            });
        });
    });

This code always fail, if I put the td.verify within a try-catch it pass but as a false positive.

I think I might be able to verify a call without side effects, but I have no sure if it is a bug or something that I could not understand or do correctly.

@andreventuravale
Copy link
Author

andreventuravale commented Sep 19, 2017

I did found a way to do it:

expect(td.explain(this.closure).callCount).to.be.greaterThan(0);

Not sure if it is correct though.
Thanks.

@searls
Copy link
Member

searls commented Mar 24, 2018

Two notes:

1.) It's not necessary to verify calls that you have also stubbed, so this shouldn't be a real issue. If the verification feels necessary then the stub must not be necessary.

2.) Because the stubbing throws an error, a td.verify demonstration will also throw an error. Your only option if you really want to do this is as you stated.

@searls searls closed this as completed Mar 25, 2018
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