Open hyanmandian opened 4 years ago
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");
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
Nice idea! I think that uvu/spy
should solve that!
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?
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.
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.
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.
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?