Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP

Loading…

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

Open
jigargosar opened this Issue · 3 comments

2 participants

@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.

@jigargosar

I propose following implementation of assert method

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;
};
@arunoda
Owner
@arunoda
Owner

We've a another method called assertThrows()

mocked.assertThrows();
        Same as the mocked.assert() but throws an execption if rules breaks.

See this is what you want

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Something went wrong with that request. Please try again.