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

Feature: assertThrows should not succeed when a "marked to fail" method was called on mock #2

Open
realistschuckle opened this issue Jan 29, 2014 · 2 comments

Comments

@realistschuckle
Copy link
Owner

From Feature: assertThrows should not succeed when a "marked to fail" method was called on mock (Issue #14) from @jigargosar:

I really am missing this feature.

I have marked a method to fail. And need to assert the fact in test that that method was never called.

In this particular case, the mock throws an error, but the SUT catches it, since its running a loop, with try/catch in the loop.

Thus my tests are all passing. :(

Ideally if assertThrows would throw an exception when any method was called on mock that was marked for failure, this wouldn't let my test pass.

Is it possible to easily integrate this feature?

thanks.

this.assert = function() {      
    var success = true;
    for(var method in entries) {
        var entriesForMethod = entries[method];
        entriesForMethod.forEach(function(entry) {
            if(!entry.shouldFail && entry.executed == false) {
                success = false;
                console.error(
                        "method call for: '" + method + "()' with params: " + getParamString(entry.args) + " was not executed!\n"
                );
            }
            if(entry.shouldFail && entry.executed){
                success = false;
                console.error(
                        "method call for: '" + method + "()' with params: " + getParamString(entry.args) + " should not be executed!\n"
                );
            }
        });
    }

    return success;
};
@realistschuckle
Copy link
Owner Author

In other mocking frameworks, the fail method would have a name like raiseError or throws. The assertThrows is a method that raises an Error when asserting that the test has met the expectations of the mock unlike the assert method that just writes stuff to console.error. We will fix this confusion, I think, in the next major release.

@realistschuckle
Copy link
Owner Author

I have just created an interim milestone that will act as a bridge between versions 0.3 and 1.0. I will address this issue in that release.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

1 participant