-
-
Notifications
You must be signed in to change notification settings - Fork 62
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
Best way to test memoized functions? #88
Best way to test memoized functions? #88
Comments
@plasticrake Firstly, tests confirming that memoization works as expected are included in Still I understand that you may want to conduct some sanity check, to confirm that indeed given function is memoized (so wrappped with Doing that library agnostic way would be to just run function twice and configure tests against observed side effects. Here I'm not sure what exactly your function does, so I'm not sure how such test should look on your side Or if that for some reason is difficult (still I would wonder why?), then you may test it in less agnostic way as e.g.: fn.__memoized__ === true I'm closing it, but you still have some doubts let's continue discussion here |
I think @plasticrake pointed out a real issue. A few tests, running on node:8.4.0: Everything works fine with this:
But it crashes with the example he gave:
It seems that the function |
I'm trying to write a test to check that my function is using the cached value. From what I can tell the only exposed properties are
__memoized__
and_has()
and_get()
.Also many of my memoized functions take no arguments and _has() and _get() don't seem to work on those.
Is there an example on the best way to test this? I looked at some of the test scripts here but it looked like it kept a 'cache miss' counter in the original function.
The text was updated successfully, but these errors were encountered: