Closed zheng-kai closed 2 years ago
Hey @zheng-kai, thank you for sharing the fruits of your research effort here.
Did you mean that your (slightly faulty) implementation passes all _.throttle
tests? That is quite impressive by itself already. My compliments.
So there is a bug in your implementation that our tests can't detect. That lack of detection I wouldn't call a bug in itself; it's impossible to cover all conceivable bugs in our unittests. Still, I agree that it would be desirable to add detection for this particular flavor, now that we know about it.
Would you like to submit a pull request and get the credit for it? I would suggest adding your modified version of the first case as an additional test case, rather than it replacing the original first case, because those two versions are testing subtly different things and there is no reason not to have both.
This is a test case that exposed the bug.
var __ = typeof require == 'function' ? require('.') : window._; // import my implement let fun = function (v) { console.log(v) } let t = __.throttle(fun,1000); t(1) t(2) t(3) /* output console 1 2 3 */ /* but the correct output should be 1 2 */
Shouldn't that be
/*
1
3
*/
?
Yes,my implementation passes all _.throttle tests. I'll submit a pull request soon. oh, the correct output should be
1
3
Thanks for your response😆
Hello, I'm a beginner to throttle.When I tried to implement the throttle function, I found that the test cases was incomplete. My throttle function will execute func as many times as it was called.But tests don't detect this bug. Here is my implement.
This is a test case that exposed the bug.
Can modify the first test case about throttle like this