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

Add uvu/spy package #10

Open
hyanmandian opened this issue Jul 9, 2020 · 7 comments · May be fixed by #32
Open

Add uvu/spy package #10

hyanmandian opened this issue Jul 9, 2020 · 7 comments · May be fixed by #32
Labels

Comments

@hyanmandian
Copy link
Contributor

hyanmandian commented Jul 9, 2020

Hello @lukeed, I'm solving #9 issue, and when doing the tests I discover that your assert library doesn't have a way to test if some function was called. In other libraries like jest we can do it by creating some reference to a mock function (jest.fn()for example) and after that, check if this function was called. What do you think about this feature?

@hyanmandian
Copy link
Contributor Author

hyanmandian commented Jul 9, 2020

Just to give you some example about my idea:

const exampleCallback = assert.fn();

exampleCallback("foo", "foobar");
exampleCallback("bar");

// just check if was called
assert.called(exampleCallback);

// check how many times was called
assert.equal(exampleCallback.calls.length, 2)
// or create some facade to previous assert
assert.calledTimes(exampleCallback, 2);

// check if correct params was passed where first array is the called function and the second is the param order
assert.calledWith(exampleCallback.calls[0][0], "foo");
assert.calledWith(exampleCallback.calls[0][1], "foobar");
assert.calledWith(exampleCallback.calls[1][0], "bar");

@lukeed
Copy link
Owner

lukeed commented Jul 9, 2020

Hey,

I don't think this really belongs in assert since it will leading into a full mocking/spying utility. Perhaps I can add that as a uvu/spy entry at some point, but for now, uvu works really well with sinon which does all the things you're asking for

@hyanmandian
Copy link
Contributor Author

Nice idea! I think that uvu/spy should solve that!

@lukeed
Copy link
Owner

lukeed commented Jul 9, 2020

Cool. It might be a while before I can get to that, simply because the sinon solution is already feature complete. Perhaps a 1.0 thing?

Should I put up a sinon example in the meantime?

@hyanmandian
Copy link
Contributor Author

I think that's no problem for a while, you already say in the README that uvu works with any assert library. I created this issue just to check if spy helps is in the roadmap of this project.

@lukeed lukeed added the future label Jul 10, 2020
@lukeed lukeed changed the title Add called assertion Add uvu/spy package Jul 10, 2020
@therealparmesh
Copy link

I too was looking for a small alternative to Sinon or Jest for spy functionality to pair with Uvu.

Might I suggest https://github.com/therealparmesh/snoop until Uvu reaches this point in the roadmap?

I'm going to publish the first version pretty soon and would greatly appreciate any guidance from the community.

@lukeed
Copy link
Owner

lukeed commented Jul 14, 2020

Looks great @therealparmesh! Awesome alternative (and name 😆)!

I think uvu/spy will still exist at some point in the future, but this is definitely a viable option.

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

Successfully merging a pull request may close this issue.

3 participants