Issue
Hello, I have been trying to assert with jest that the call to the method observe behind a call to labels on an Histogram works.
However it doesn't because the function returned by the method labels are referencing directly the function without passing the reference to the corresponding method (observe and startTimer).
It is not a big deal because it is for testing purpose on my case but maybe someone need to keep the reference at some point.
Solution
Instead of returning
return {
observe: observe.call(this, labels),
startTimer: startTimer.call(this, labels),
};
We could return
return {
observe: this.observe.bind(this, labels),
startTimer: this.startTimer.bind(this, labels),
};
Alternative
It is not a blocking point at all.
On my side I changed the call I was making from histogram.labels(LABELS).observe(VALUE) to histogram.observe({ LABELS }, VALUE).
Concern
If we make change it means that the current behavior change too because it is not the same reference.
So maybe it is something wanted initially ?
Next steps
Can I make a pull request with that change ?
Or maybe someone has a work around with jest ?
I am spying the method like this
jest.spyOn(histogram, 'observe')
Issue
Hello, I have been trying to assert with jest that the call to the method
observebehind a call tolabelson an Histogram works.However it doesn't because the function returned by the method
labelsare referencing directly the function without passing the reference to the corresponding method (observeandstartTimer).It is not a big deal because it is for testing purpose on my case but maybe someone need to keep the reference at some point.
Solution
Instead of returning
We could return
Alternative
It is not a blocking point at all.
On my side I changed the call I was making from
histogram.labels(LABELS).observe(VALUE)tohistogram.observe({ LABELS }, VALUE).Concern
If we make change it means that the current behavior change too because it is not the same reference.
So maybe it is something wanted initially ?
Next steps
Can I make a pull request with that change ?
Or maybe someone has a work around with jest ?
I am spying the method like this
jest.spyOn(histogram, 'observe')