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

ArgumentCaptor to easily verify complex argument values #36

Open
danail-branekov opened this issue May 23, 2015 · 1 comment
Open

ArgumentCaptor to easily verify complex argument values #36

danail-branekov opened this issue May 23, 2015 · 1 comment

Comments

@danail-branekov
Copy link

Hi,

Mockito offers a convenient tool called ArgumentCaptor which is really useful for analyzing actual argument values - http://docs.mockito.googlecode.com/hg/org/mockito/ArgumentCaptor.html
I just noticed that JsMockito is missing this feature
Here is my implementation, I would be glad to make it part of JsMockito :)

function ArgumentCaptor() {
    var val;
}

ArgumentCaptor.prototype.capture = function () {
    var that = this;
    return new JsHamcrest.SimpleMatcher({
        matches: function (actual) {
            that.val = actual;
            return true;
        },

        describeTo: function (description) {
            description.append("Argument Captor");
        }
    });
};

ArgumentCaptor.prototype.getValue = function () {
    return this.val;
};

Here is an example usage:

var mockedFunction = JsMockito.mockFunction();
var argsCaptor = new ArgumentCaptor();
JsMockito.verify(mockedFunction)(argsCaptor.capture());
var invocationArgs = argsCaptor.getValue();
// verify invocationArgs here
@Tzrlk
Copy link

Tzrlk commented Apr 11, 2016

Raise a pull request?

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