-
Notifications
You must be signed in to change notification settings - Fork 5
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
Ability to assert what arguments a method was called with #21
Comments
Sounds good to me! I like the first option but right now it doesn’t seem to fit under calls to me. Going to think about it. @ebebbington @Guergeiro @saragee3 thoughts? |
I think it makes sense to be honest, it's another way for assertions, and i think it'll be a good feature dev might want to use I too like the first option |
I approve any of the options. Will any of the implementations change the API of the function? Remember that we already released v1, so we can't change the API. Changing the signature to add fields is okay. |
I think this is how we should go about it. It won't break the API. However, it does mean we'll have a list of reserved properties that a mock will have and we'll need to document that. In the Sockets repo, we have a list of reserved events, so I'm ok with having a list of reserved properties. const mock = Rhum
.mock(Server)
.withConstructorArgs("arg1", "arg2", "arg3")
.create();
// constructor_args is reserved
Rhum.asserts.assertEquals(mock.constructor_args.methodToTest, ["arg1", "arg2", "arg3"]);
mock.methodToTest("arg1", "arg2", "arg3");
// function_args is reserved
Rhum.asserts.assertEquals(mock.function_args.methodToTest, ["arg1", "arg2", "arg3"]);
// calls is reserved
Rhum.asserts.assertEquals(mock.calls.methodToTest, 1); |
@crookse I like this solution. Two things:
|
|
Using |
Summary
What: Now, that there are stubs and mocks, it would be great if we could check with what argument they were called with.
Why: It helps to check correct behaviour and it exists in other frameworks too. eg: Jasmine's
toHaveBeenCalledWith
Acceptance Criteria
Example Pseudo Code (for implementation)
Will have to figure out where it should be accessed from.
Maybe
mock.calls.methodToTest
should return an object with{ count: number, lastArgs: any[]}
, but it would change current signature.Or maybe
mock.calls.args.methodToTest
but than if there is a method namedargs
it would cause problemsThe text was updated successfully, but these errors were encountered: