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

"times" seems superfluous #343

Open
Jameskmonger opened this issue Mar 30, 2017 · 7 comments
Open

"times" seems superfluous #343

Jameskmonger opened this issue Mar 30, 2017 · 7 comments

Comments

@Jameskmonger
Copy link
Contributor

The times property in Expect(some.function).toHaveBeenCalled(3).times seems very unnecessary. I think that as a library we should be encouraging good, clean code - not using variables which don't do anything but increase readability.

I find it to be slightly confusing if I don't understand the library - why is someone using a variable as a statement?

If you want to keep a syntax, maybe we could do something like FakeItEasy:

Expect(some.function).toHaveBeenCalled(Repeated.Times(5))
@jamesadarich
Copy link
Member

@Jameskmonger yeah, let's have this as a discussion task to find a way to implement the current functionality. This will have to go in > 2.0.0 as it's an API change 👍

@Jameskmonger
Copy link
Contributor Author

Expect(some.function).toHaveBeenCalled();
Expect(some.function).toHaveBeenCalled(Repeated.Exactly.Times(3));
Expect(some.function).toHaveBeenCalled(Repeated.AtLeast.Times(3));
Expect(some.function).toHaveBeenCalled(Repeated.AtMost.Times(3));

I think the above syntax is good for toHaveBeenCalled - toHavebeenCalledWith will take more thought.

@jamesadarich
Copy link
Member

I think we should probably leave the Repeated out in this case as it's a bit of extra unnecessary (and that's what we're trying to achieve in this task ;) )

Will need a bit more thought for toHaveBeenCalledWith

Probably the neatest I can think of now is similar to how it is now.

Expect(some.function).toHaveBeenCalledWith().exactly.times(4);
Expect(some.function).toHaveBeenCalledWith().atLeast.times(4);
Expect(some.function).toHaveBeenCalledWith().atMost.times(4);

Expect(some.function).toHaveBeenCalledWith("some", "arguments").exactly.times(4);
Expect(some.function).toHaveBeenCalledWith("some", "arguments").atLeast.times(4);
Expect(some.function).toHaveBeenCalledWith("some", "arguments").atMost.times(4);

@Jameskmonger
Copy link
Contributor Author

Perfect, that looks good to me @jamesrichford.

@jamesadarich
Copy link
Member

Another thought on this one @Jameskmonger maybe we should remove the extra dot chain i.e.

Expect(some.function).toHaveBeenCalledWith().exactlyTimes(4);
Expect(some.function).toHaveBeenCalledWith().atLeastTimes(4);
Expect(some.function).toHaveBeenCalledWith().atMostTimes(4);

Expect(some.function).toHaveBeenCalledWith("some", "arguments").exactlyTimes(4);
Expect(some.function).toHaveBeenCalledWith("some", "arguments").atLeastTimes(4);
Expect(some.function).toHaveBeenCalledWith("some", "arguments").atMostTimes(4);

@Jameskmonger
Copy link
Contributor Author

Potentially we could, but I think it may fit well with our not modifier.

@jamesadarich
Copy link
Member

@Jameskmonger where would the not be here?

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

2 participants