You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
When I install jasmine's mock clock, create a debounced function using lodash's implementation of _.debounce, invoke the debounced function and tell jasmine.clock() to .tick() beyond the debounce interval, a strange behavioral bifurcation occurs:
when run normally, the test fails (debounced function is never invoked);
when stepping through the code with a debugger, the test passes (debounced function is invoked).
Are you creating an issue in the correct repository?
Maybe. This might be a bug in jasmine-core or in lodash. Since lodash.debounce appears to do the right thing in general, I'm trying Jasmine first.
Expected Behavior
The example suite should always pass.
Current Behavior
The example suite fails when run normally but passes when stepping through the code with a debugger.
Possible Solution
One apparent difference between the underscore implementation and the lodash implementation is that lodash inspects the numerical value of the current time while underscore does not. If the problem is in jasmine-core, then one of the possibilities is that the current time is somehow reported in an incorrect or incoherent way. However, I cannot explain why debugging would change this.
constlodash=require('lodash');describe('jasmine.clock',function(){consttimeout=200;beforeEach(function(){jasmine.clock().install();});afterEach(function(){jasmine.clock().uninstall();});it('interacts strangely with lodash.debounce',function(){letstate='initial';consttrigger=lodash.debounce(transition,timeout);trigger();jasmine.clock().tick(timeout-1);expect(state).toBe('initial');// Insert breakpoint here to make the test pass.jasmine.clock().tick(2);expect(state).toBe('final');functiontransition(){state='final';}});});
Context
I am implementing a state machine with machina.js where some transitions are triggered automatically after a timeout. Some inputs should delay this transition, which is why I am using _.debounce. The fact that the test fails, except when I try to debug it, is really unhelpful.
Your Environment
Version used: 3.2.1 as well as 3.5.0
Environment name and version: node.js 10.19.0, Safari 13.0.5, Firefox 73.0.1
Operating System and version: macOS 10.14.6 (Mojave)
I have resolved my issue. My earlier observation, that lodash uses the numerical value of the current time while underscore does not, turned out to be the crucial difference.
After finding lodash/lodash#3559 and then jestjs/jest#3465, I realized that I needed to not only .install() the mock clock but also to invoke .mockDate() on it. I had seen this method mentioned in the Jasmine documentation before, but didn't make the connection until now.
So no bug in either library after all (although I'd argue that the lodash implementation of debounce looks overly complicated compared to the underscore implementation). Closing.
When I install jasmine's mock clock, create a debounced function using lodash's implementation of
_.debounce
, invoke the debounced function and telljasmine.clock()
to.tick()
beyond the debounce interval, a strange behavioral bifurcation occurs:See https://gitlab.com/jgonggrijp/jasmine-clock-debounce-testcase for a packaged, ready-to-run reduced testcase.
Are you creating an issue in the correct repository?
Maybe. This might be a bug in jasmine-core or in lodash. Since lodash.debounce appears to do the right thing in general, I'm trying Jasmine first.
Expected Behavior
The example suite should always pass.
Current Behavior
The example suite fails when run normally but passes when stepping through the code with a debugger.
Possible Solution
One apparent difference between the underscore implementation and the lodash implementation is that lodash inspects the numerical value of the current time while underscore does not. If the problem is in jasmine-core, then one of the possibilities is that the current time is somehow reported in an incorrect or incoherent way. However, I cannot explain why debugging would change this.
Suite that reproduces the behavior (for bugs)
The example suite below omits the underscore version; see https://gitlab.com/jgonggrijp/jasmine-clock-debounce-testcase for the full reduced testcase.
Context
I am implementing a state machine with machina.js where some transitions are triggered automatically after a timeout. Some inputs should delay this transition, which is why I am using
_.debounce
. The fact that the test fails, except when I try to debug it, is really unhelpful.Your Environment
The text was updated successfully, but these errors were encountered: